Comments (8)
These are meant only for documentation and metadata purposes. Having Guzzle throw an exception would mean that it would require much more metadata on how to convert a response or network error into an exception class. Guzzle would also need some kind of factory to create exceptions. I've intentionally omitted throwing custom exceptions to avoid this complexity.
With that said, you could utilize this metadata by creating a subscriber that listens for errors, checks metadata for errorResponses, and throws the appropriate exception.
On Jan 1, 2015, at 4:50 PM, Michaël Gallego [email protected] wrote:
Hi,
In the Operation descriptor, there is a "errorResponses" hash that is supposed to be used. While it's read by the operation, it seems to be never used elsewhere in the code. As a consequence, user defined exception are never triggered.
Did I miss something or is the doc outdated? :)
Thanks!
—
Reply to this email directly or view it on GitHub.
from guzzle-services.
I see... What if I write a reusable subscriber? I've checked my various Guzzle 3 integrations and I actually use this all the time, so that would mean duplicate the same code everywhere. While I understand that it does not throw exception by default, at least it should have a default one :).
from guzzle-services.
What do you mean by having a default one?
On Jan 1, 2015, at 5:19 PM, Michaël Gallego [email protected] wrote:
I see... What if I write a reusable subscriber? I've checked my various Guzzle 3 integrations and I actually use this all the time, so that would mean duplicate the same code everywhere. While I understand that it does not throw exception by default, at least it should have a default one :).
—
Reply to this email directly or view it on GitHub.
from guzzle-services.
Well, having a default listener that you can attach, and that will reuse the "errorResponses" to create an exception. It won't be registered by default, but at least it removes the need to write this boilerplate code in all libraries.
from guzzle-services.
Hi,
I tried to do this this morning, unfortunately I didn't found any way to attach a listener to a command error from my client. If I hook to the "error" event, then I cannot have access to the command. Is there any way to do that simply, or am I forced to overload the __call, manually creating the command, attaching a subscriber, and trigger it?
EDIT: never mind, I had to attach the listener to the Service client, not HTTP client.
from guzzle-services.
Actually, the problem is that the current operation cannot be retrieved from a command... still trying to work around this =).
from guzzle-services.
Still no luck with this @mtdowling . Is there a simple way to add a listener that will be able to have the response AND the command that was executed (along with the errorResponses array). This is pretty necessary to do the reusable error exception listener.
from guzzle-services.
You have access to the operation information from the client that is pass around as part of each command event. You can retrieve the service description from the client and the specific operation information from the description using the name of the command.
Something like this:
use GuzzleHttp\Command\Event\ProcessEvent;
$command->getEmitter()->on('process', ProcessEvent $e) {
$name = $e->getCommand()->getName();
$description = $e->getClient()->getDescription();
$operation = $description->getOperation($name);
$errors = $operation->getErrorResponses();
// do something with the errors.
});
from guzzle-services.
Related Issues (20)
- Recommended test setup? HOT 1
- Unable to POST multipart parameters HOT 1
- Is there a way to put other models definition for list items ? HOT 1
- Raw request body data HOT 3
- What am i doing wrong ? HOT 3
- Please document how to use middleware with GuzzleClient HOT 1
- Better responseModel/responseClass feature. HOT 2
- Create request without root key HOT 1
- Support for Multiple `type` Options within Response Models
- Tests Fail with guzzlehttp/psr7 >= 1.6.0 HOT 1
- Feature Request - Ability to Bind Parameter Filters to Specific Request Stages
- What branch is under active development? HOT 2
- Feature Request: Ability to Specify "process: false" at Operation Level
- State of the project HOT 8
- guzzlehttp/guzzle dosn't work after update php to php 8 HOT 2
- Not possible to install on PHP <=7.3 HOT 2
- Why headers are not being passed ?
- Ran into composer issue because package does not auto update. HOT 5
- Extending a parameter that extends another parameter doesn't work as expected
- Add default property into response model HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from guzzle-services.