HttpError is called with response body
Hi @henvo - thanks for creating this library. For background, I am trying to hook react-admin up to a Laravel back end using https://laraveljsonapi.io/. It's going okay so far.
I noticed that when an HTTP error occurs (for example because of sending an attribute that isn't allowed), react-admin shows a blank screen and I get a console error Polyglot.transformPhrase expects argument #1 to be string.
I had a look at the error handling and the following code treats the entire response body a message field for the error: https://github.com/henvo/ra-jsonapi-client/blob/master/src/initializer.js#L39
The JSON:API spec says that errors should include a top-level errors array:
https://jsonapi.org/format/1.1/#errors
And indeed this is what laravel-json-api returns:
{
"jsonapi":{
"version":"1.0"
},
"errors":[
{
"detail":"The field companyId is not a supported attribute.",
"source":{
"pointer":"\/data\/attributes"
},
"status":"400",
"title":"Non-Compliant JSON:API Document"
}
]
}
I am unfamiliar with what level of detail react-admin supports for errors, but perhaps we should attempt to extract error information from the response, and fall back to using the entire response body only if it's a string.
Happy to submit a PR if it might be accepted.