plivo-node/lib/utils/restException.js
narayana shanubhogh dda00548e8 exception handle
2021-05-04 12:08:56 +05:30

20 lines
596 B
JavaScript

class PlivoRestError extends Error {
constructor(response) {
response = response.response
var body;
super('[HTTP ' + response.status + '] Failed to execute request');
try {
body = typeof response.data === 'string' ? JSON.parse(response.data) : response.data;
} catch (err) {
body = {"error": response.data, "api_id": ''}
}
this.status = response.status;
this.statusText = response.statusText
this.message = body.error;
this.apiID = body.api_id;
this.moreInfo = response.config.data
}
}
module.exports = PlivoRestError;