Giter VIP home page Giter VIP logo

Comments (13)

markushausammann avatar markushausammann commented on June 9, 2024

I'm actually not even sure if it's a good idea to have this parseResponse method at all. You should just return the response so the consuming entity can deal with it as it pleases. Or, if you really want to process the response for the user, you need to map the possible API error responses as listed here http://developer.postmarkapp.com/developer-api-overview.html#error-codes and return this information to the consuming entity.

from slmmail.

bakura10 avatar bakura10 commented on June 9, 2024

Hi,

The reason we did unify the exception is to make it possible to switch from one provider to another without changing code. This is because some providers like elasticemail have VERY POOR support for errors, so this way we are able to make everything works the same. So I think this is a good idea. You can catch for SlmMail exception interface, even without knowing which provider you are using internally.

However, I agree that any exception that we could set as previous exception should be done. Don't hesitate to do a PR if you feel this way, we will be glad to review.

Envoyé de mon iPhone

Le 6 nov. 2014 à 17:16, Markus [email protected] a écrit :

I'm actually not even sure if it's a good idea to have this parseResponse method at all. You should just return the response so the consuming entity can deal with it as it pleases. Or, if you really want to process the response for the user, you need to map the possible API error responses as listed here http://developer.postmarkapp.com/developer-api-overview.html#error-codes and return this information to the consuming entity.


Reply to this email directly or view it on GitHub.

from slmmail.

markushausammann avatar markushausammann commented on June 9, 2024

Another problem is that the parseResponse is private, which means I can't even override it to solve the problem in my Service extension. I don't feel like providing a pull request after what you've done with my last one. You're welcome for my efforts to point the problems out to you, though. Happy fixing.

from slmmail.

juriansluiman avatar juriansluiman commented on June 9, 2024

@markushausammann the API error codes postmark provides are only valid for 422 errors. The exception you highlight is the generic RuntimeException, but actually a ValidationErrorException is thrown with a specific message (postmark calls this not a "validation error" but "input error", the idea is the same). I am talking about this exception.

Would it be sufficient to set an exception code besides the message for you? Then you can catch the specific exception and grab the exception code. It will change SlmMail to this:

case 422:
    $code    = (int) $result['ErrorCode'];
    $message = sprintf(
        'An error occured on Postmark (error code %s), message: %s',
        $result['ErrorCode'],
        $result['Message']
    );
    throw new Exception\ValidationErrorException($message, $code);

Your userland code will become then:

use SlmMail\Service\Exception\ValidationErrorException;

try {
    $transport->send($message);
} catch (ValidationErrorException $e) {
    $code = $e->getCode();
    // handle $code according to
    // http://developer.postmarkapp.com/developer-api-overview.html#error-codes
}

Another problem is that the parseResponse is private, which means I can't even override it to solve the problem in my Service extension.

As with my above example, I don't think (yet) you need to override the method. If the above example is not enough for your use case, please elaborate so we can think along your lines to help.

from slmmail.

markushausammann avatar markushausammann commented on June 9, 2024

@juriansluiman yes, making the actual ErrorCode and Message extractable from the Exception would be the perfect solution, please change it in that way! This is really important because the reasons for the 422 response are very diverse and some of them can be handled gracefully and don't even need logging. For example 406 can happen and can easily be handled. 405 should probably alert somebody, 10 and 400 should log with high priority, etc.

from slmmail.

juriansluiman avatar juriansluiman commented on June 9, 2024

Closing, see #84

from slmmail.

markushausammann avatar markushausammann commented on June 9, 2024

Thank you!

from slmmail.

markushausammann avatar markushausammann commented on June 9, 2024

@juriansluiman would you mind tagging a minor release?

from slmmail.

juriansluiman avatar juriansluiman commented on June 9, 2024

Yes, but let's await merging first ;-)

from slmmail.

markushausammann avatar markushausammann commented on June 9, 2024

Sure, I thought you had that power :)

from slmmail.

markushausammann avatar markushausammann commented on June 9, 2024

Or is it running a build on travis or smth?

from slmmail.

juriansluiman avatar juriansluiman commented on June 9, 2024

@markushausammann all PRs are running against Travis and I prefer the policy not to merge PRs myself. So Michael reviews mines and vice versa (most of the times). Now all is green & merged, I tagged v1.5.1

from slmmail.

markushausammann avatar markushausammann commented on June 9, 2024

Many thanks!

from slmmail.

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.