Skip to content

Commit ac35004

Browse files
committed
adapters/application: Fix JSON payload parsing for error responses when using fetch() internally
1 parent cdf8df6 commit ac35004

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

app/adapters/application.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,17 @@ export default RESTAdapter.extend({
1414

1515
return {};
1616
}),
17+
18+
handleResponse(status, headers, payload, requestData) {
19+
if (typeof payload === 'string') {
20+
try {
21+
payload = JSON.parse(payload);
22+
} catch (ignored) {
23+
// if the payload can't be parsed as JSON then let's continue
24+
// with the string payload
25+
}
26+
}
27+
28+
return this._super(status, headers, payload, requestData);
29+
},
1730
});

0 commit comments

Comments
 (0)