Make full response JSON available to consumers of APIError #195
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Background
Some of the users in my app have invalid email addresses, according to mailjet. This is my bad -- Mailjet evidently uses a different email address validation format to rails (I'm using
URI::MailTo::EMAIL_REGEXP
). But I wanted to "handle" the error I receive from mailjet, and if the email is reported invalid, mark the user as needing manual intervention to "fix" the problem (or delete the account, etc).Error handling in Mailjet
The error message I receive from Mailjet contains the following JSON:
(produced using
Mailjet::Send({'To' => [{'Email' => "" }]})
)This doesn't seem to match the format that
ApiError
is expecting, and henceself.reason
is blank with this error condition.What I've done here is to make available the fully parsed error message -- for now -- but this is probably the wrong approach.
I think the correct approach is to make
ApiError
correctly interpret this type of error response, and provide amailjet_codes
(I see that there can be multiple messages, each with multiple errors, so making a single code available also doesn't seem like the right approach).Until then, by making available the full response object, I can do stuff like this:
Happy to make this better if you give me some pointers on what and where to enhance.