postmark-php icon indicating copy to clipboard operation
postmark-php copied to clipboard

Handle unexpected responses gracefully

Open AndyWendt opened this issue 3 years ago • 0 comments

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.

  1. Extracted a function, using PHPStorm built-in refactorings, to handle responses
  2. Promoted, using PHPStorm built-in refactorings, said function to a class
  3. Backfilled tests and, along the way, renamed and restructured the code
  4. Extracted factory methods to internalize the knowledge of the construction of PostmarkException
  5. Handled potentially missing ErrorCode and or Message 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.

AndyWendt avatar Mar 26 '21 21:03 AndyWendt