Skip to content
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

HttpError is called with response body #55

Open
euoia opened this issue Dec 11, 2022 · 0 comments
Open

HttpError is called with response body #55

euoia opened this issue Dec 11, 2022 · 0 comments

Comments

@euoia
Copy link

euoia commented Dec 11, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant