postmark-php
postmark-php copied to clipboard
Handle unexpected responses gracefully
Today, I noticed an interesting issue where I received a 404
response with no ErrorCode
or Message
fields in the body. This broke the exception handling in the code. The cause I believe was that I tried to send a batch that was too large in size (not in number).
Anyway, for the fun stuff.
- Extracted a function, using PHPStorm built-in refactorings, to handle responses
- Promoted, using PHPStorm built-in refactorings, said function to a class
- Backfilled tests and, along the way, renamed and restructured the code
- Extracted factory methods to internalize the knowledge of the construction of
PostmarkException
- Handled potentially missing
ErrorCode
and orMessage
keys in the response body by using the PHP 7.0 compatible null coalescing operator.
There are a couple of defaults that need maintainer input.