fix(common): attempt to JSON.parse errors for JSON responses (#19773)
PR Close #19773
This commit is contained in:

committed by
Tobias Bosch

parent
25cbc98979
commit
04ab9f1917
@ -191,6 +191,14 @@ export class HttpXhrBackend implements HttpBackend {
|
||||
// The parse error contains the text of the body that failed to parse.
|
||||
body = { error, text: body } as HttpJsonParseError;
|
||||
}
|
||||
} else if (!ok && req.responseType === 'json' && typeof body === 'string') {
|
||||
try {
|
||||
// Attempt to parse the body as JSON.
|
||||
body = JSON.parse(body);
|
||||
} catch (error) {
|
||||
// Cannot be certain that the body was meant to be parsed as JSON.
|
||||
// Leave the body as a string.
|
||||
}
|
||||
}
|
||||
|
||||
if (ok) {
|
||||
|
Reference in New Issue
Block a user