mirror of
https://github.com/flarum/framework.git
synced 2025-01-19 07:42:48 +08:00
Only parse as JSON if appropriate content type
This commit is contained in:
parent
7127bea15e
commit
e1315d27a4
|
@ -202,13 +202,7 @@ export default class App {
|
|||
// When we deserialize JSON data, if for some reason the server has provided
|
||||
// a dud response, we don't want the application to crash. We'll show an
|
||||
// error message to the user instead.
|
||||
options.deserialize = options.deserialize || (responseText => {
|
||||
try {
|
||||
return JSON.parse(responseText);
|
||||
} catch (e) {
|
||||
throw new RequestError(500, responseText, options);
|
||||
}
|
||||
});
|
||||
options.deserialize = options.deserialize || (responseText => responseText);
|
||||
|
||||
options.errorHandler = options.errorHandler || (error => {
|
||||
throw error;
|
||||
|
@ -233,7 +227,13 @@ export default class App {
|
|||
throw new RequestError(status, responseText, options, xhr);
|
||||
}
|
||||
|
||||
return responseText;
|
||||
if (xhr.getResponseHeader('content-type').indexOf('json') !== -1) {
|
||||
try {
|
||||
return JSON.parse(responseText);
|
||||
} catch (e) {
|
||||
throw new RequestError(500, responseText, options, xhr);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if (this.requestError) this.alerts.dismiss(this.requestError.alert);
|
||||
|
|
Loading…
Reference in New Issue
Block a user