Skip to content

Commit

Permalink
There are cases where payload is an object, and normalizeErrorRespons… (
Browse files Browse the repository at this point in the history
#8621)

* There are cases where payload is an object, and normalizeErrorResponse ends up returning [object Object] for "detail"

* Add comment about JSON.stringify

* Update rest.ts
  • Loading branch information
NullVoxPopuli authored May 25, 2023
1 parent b502ee7 commit 387c167
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/adapter/src/rest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1276,7 +1276,11 @@ class RESTAdapter extends Adapter.extend(BuildURLMixin) {
{
status: `${status}`, // Set to a string per the JSON API spec: https://jsonapi.org/format/#errors
title: 'The backend responded with an error',
detail: `${payload}`,
// Detail is intended to be a string, but backends be non-compliant.
// stringifying gives the user a more friendly error in this situation, whereas
// they'd instead receive [object Object].
// JSON.stringify will convert *anything* to a string without erroring.
detail: typeof payload === 'string' ? payload : JSON.stringify(payload),
},
];
}
Expand Down

0 comments on commit 387c167

Please sign in to comment.