Open tofumatt opened 2 months ago
@jamesozzie @tofumatt please could you confirm next steps on this one?
@binnieshah I have a documentation task for this which I'll update today and send to @adamdunnage for review.
@tofumatt Do you know the error code for this, so I can add to the mapping sheet?
Hey @tofumatt I've written the IB here, the key challenge here is that we don't have a schema definition consistently for each REST API. The closest we have for some APIs in on the PHP side:
To roll this out across all of our APIs will require defining the schema across all of these APIs in a reliable way. In the IB I propose an approach for this and suggest starting with the getReport
request as it is the most used API as well as the one that it effected by the issue caused by the Transliterator plugin. As we apply this to different stores we could extract the logic that compares the schema to the response into a reusable helper to use in other stores.
@benbowler, i think the main idea here is not to verify responses to match certain schemas but to detect when an API request returns a response that is not a JSON object. In other words, if the request fails and returns non-JSON response, we should craft a special error and dispatch it in the catch
section: https://github.com/google/site-kit-wp/blob/45ca3ddd422f59f2ae0250c038783887c913d8c7/assets/js/googlesitekit/api/index.js#L183-L209
@eugene-manuilov well, in the issue that caused this ticket to be created (#8442) the JSON returned from the API was still valid JSON, but the expected JSON format for the report had been modified by the Transliterator plugin. Specifically, arrays had been restructured to numerically indexed objects in the response.
@benbowler, ah.. thanks for clarifying that, i didn't notice that.
- Update
assets/js/googlesitekit/data/create-fetch-store.js
, adding an optional prop,validateResponse
, which defaults to an empty function that simply passes through all props unchanged.
Let's probably just add a new property schema
to createFetchStore
arguments instead of validateResponse
. If a schema is passed the fetch store should automatically verify it.
Feature Description
Based on #8442, we should detect specific malformed WP REST API JSON responses and display a bespoke error message for them with links to a help document that addresses those errors.
The help page should reference plugin(s) (like Transliterator plugin in #8442) that are known to cause these errors.
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
Implementation Brief
[ ] Update
assets/js/googlesitekit/data/create-fetch-store.js
, adding an optional prop,validateResponse
, which defaults to an empty function that simply passes through all props unchanged.[ ] Update the
RECEIVE
reducer case to callvalidateResponse
before callingreducerCallback
.[ ] Update
assets/js/modules/analytics-4/datastore/report.js
, create and newREPORT_SCHEMA
object like so: