Issue #3276720: Add ability to implement custom error handler
- Adds
onError
property to the DrupalState class that allows for custom function to handle thrown errors - Adds some better error messages for when Drupal responds to a fetch with 404 (see the fetch wrappers
fetchApiIndex
andfetchJsonapiEndpoint
- Adds tests for the custom
onError
handler and the new error messages
If the original error messages from Drupal are needed, we can add a flag so that the default is to not catch or enhance any errors coming from Drupal. The reason I did not do it this way to start is that the errors from Drupal were not helpful (for example: 'unexpected token < in JSON position 2'. This doesn't seem helpful to me, but 'Tried to fetch example.com/not-valid. Status code: 404' seems better. Thoughts?)
I also decided to wait on trying to implement onErrorRetry
until this portion of the feature was reviewed.
Closes #3276720