Giter Club home page Giter Club logo

Comments (8)

mtdowling avatar mtdowling commented on May 7, 2024

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.

bakura10 avatar bakura10 commented on May 7, 2024

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.

mtdowling avatar mtdowling commented on May 7, 2024

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.

bakura10 avatar bakura10 commented on May 7, 2024

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.

bakura10 avatar bakura10 commented on May 7, 2024

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.

bakura10 avatar bakura10 commented on May 7, 2024

Actually, the problem is that the current operation cannot be retrieved from a command... still trying to work around this =).

from guzzle-services.

bakura10 avatar bakura10 commented on May 7, 2024

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.

mtdowling avatar mtdowling commented on May 7, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.