Enhance error message extraction and move class to more appropriate namespace#145
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
JasonTheAdams
left a comment
There was a problem hiding this comment.
Small suggestion, but otherwise looks good!
| if ( | ||
| isset($data[0]) && | ||
| is_array($data[0]) && | ||
| isset($data[0]['error']) && | ||
| is_array($data[0]['error']) && | ||
| isset($data[0]['error']['message']) && | ||
| is_string($data[0]['error']['message']) | ||
| ) { |
There was a problem hiding this comment.
You don't need to check each layer. PHP supports checking multiple layers down. 👍
| if ( | |
| isset($data[0]) && | |
| is_array($data[0]) && | |
| isset($data[0]['error']) && | |
| is_array($data[0]['error']) && | |
| isset($data[0]['error']['message']) && | |
| is_string($data[0]['error']['message']) | |
| ) { | |
| if (isset($data[0]['error']['message']) && is_string($data[0]['error']['message'])) { |
There was a problem hiding this comment.
But PHPStan hates it 😢
Some provider API endpoints, such as those from Google may return an array of error objects with message inside. This PR enhances the
ErrorMessageExtractorto account for that shape, leading to more helpful error messages.Additionally, I noticed there's both a
Providers\Http\Utilnamespace and aProviders\Http\Utilitiesnamespace. That doesn't make any sense, so they are being combined into one as part of this PR.