-
Notifications
You must be signed in to change notification settings - Fork 121
Add support for WP-API error parsing #8031
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
You can test the changes from this Pull Request by:
|
Generated by 🚫 dangerJS |
|
The code looks good to me and it tests well! 🎉 I got three repeated error messages, but I guess it's because we log them at every level of our IAP architecture. |
|
|
||
| /// WordPress API Request Error | ||
| /// | ||
| public enum WordPressApiError: Error, Decodable, Equatable { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already have an enum for WordPress.com Request Errors (DotcomError), for me to understand, do these two enums have different purposes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is for the core API errors, which might come from WordPress.com (wpcom/v2, wp/v2) or directly from a self-hosted site (via WordPressOrgRequest). There might be some overlap, but error codes might not necessarily match.
Oh good catch. I think the "Mapping error" shouldn't be there. Previously it would only log if the error was coming from the mapper, but since I consolidated the error handling, it's too verbose now. |
Closes: #8030
Description
The existing networking code uses
DotcomValidatorandDotcomErrorto attempt to extract error information from WordPress.com API responses (error/message). However, the newer endpoints that use the core REST API (wpcom/v2,wp/v2) use a different error format (code/message/data).This PR got a bit complex, but the main idea is that each type of request can define a validator that might convert a response into an error. This is useful because a
DotcomRequestmight want to do a different thing depending on thewordpressApiVersion.Testing instructions
The easiest way to force an error is to modify
InAppPurchasesRemoteand make sure theX-APP-IDheader has an unknown identifier (e.g.Bundle.main.bundleIdentifier?.appending(".unknown")).Then:
If you test this on trunk, all you would see is a parsing error:
With the changes in this PR, you should see a more specific error:
RELEASE-NOTES.txtif necessary.