returning object

This commit is contained in:
narayana shanubhogh 2021-04-25 20:41:13 +05:30
parent 1fd103a16a
commit 8f765c90fc
2 changed files with 15 additions and 0 deletions

View file

@ -207,6 +207,19 @@ export function Axios(config) {
}
})
.catch(function (error) {
const exceptionClass = {
400: Exceptions.InvalidRequestError,
401: Exceptions.AuthenticationError,
404: Exceptions.ResourceNotFoundError,
405: Exceptions.InvalidRequestError,
500: Exceptions.ServerError,
} [error.response.status] || Error;
if (!_.inRange(error.response.status, 200, 300)) {
let body = error.response.data;
if (typeof body === 'object') {
reject(new exceptionClass(body));
}
}
reject(error.stack + '\n' + JSON.stringify(error.response.data));
})
}

View file

@ -199,6 +199,8 @@ export function Request(config) {
if (!_.inRange(response.statusCode, 200, 300)) {
body = body || response.body;
if (typeof body === 'object') {
reject(new exceptionClass(JSON.stringify(body)));
} else {
reject(new exceptionClass(body));
}
}