mirror of
https://github.com/donl/plivo-node.git
synced 2026-06-30 06:12:08 -06:00
returning object
This commit is contained in:
parent
1fd103a16a
commit
8f765c90fc
2 changed files with 15 additions and 0 deletions
|
|
@ -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));
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue