Fix error handling for large files (and endpoints called as non-json)

This commit is contained in:
Dane Everitt 2020-04-06 21:59:14 -07:00
parent 7f2b477538
commit f9878d842c
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
4 changed files with 21 additions and 12 deletions

View file

@ -29,7 +29,18 @@ export default http;
*/
export function httpErrorToHuman (error: any): string {
if (error.response && error.response.data) {
const { data } = error.response;
let { data } = error.response;
// Some non-JSON requests can still return the error as a JSON block. In those cases, attempt
// to parse it into JSON so we can display an actual error.
if (typeof data === 'string') {
try {
data = JSON.parse(data);
} catch (e) {
// do nothing, bad json
}
}
if (data.errors && data.errors[0] && data.errors[0].detail) {
return data.errors[0].detail;
}