Merge branch 'master' into fix-adaptive-ppk

This commit is contained in:
Mohammed Huzaif 2021-05-05 20:03:01 +05:30 committed by GitHub
commit eab2cdd106
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 91 additions and 8 deletions

View file

@ -3,6 +3,11 @@
## [4.17.1](https://github.com/plivo/plivo-node/releases/tag/v4.17.1)(2021-05-06)
- Added Fix for Adaptive Powerpack Create & Update functions
## [4.17.0](https://github.com/plivo/plivo-node/releases/tag/v4.17.0)(2021-05-04)
- Update library: Axios
- Add Exception Support
- Updated README
## [4.16.0](https://github.com/plivo/plivo-node/releases/tag/v4.16.0)(2021-04-19)
- Added SDK support for Voice MultiPartyCall APIs and XML

View file

@ -127,4 +127,4 @@ console.log('Phlo run result', result);
More examples are available [here](https://github.com/plivo/plivo-examples-node). Also refer to the [guides for configuring the Express server to run various scenarios](https://www.plivo.com/docs/sms/quickstart/node-expressjs/) & use it to test out your integration in under 5 minutes.
## Reporting issues
Report any feedback or problems with this version by [opening an issue on Github](https://github.com/plivo/plivo-node/issues).
Report any feedback or problems with this version by [opening an issue on Github](https://github.com/plivo/plivo-node/issues).

View file

@ -1,8 +1,11 @@
import axios from 'axios';
import queryString from 'querystring';
import * as Exceptions from '../utils/exceptions';
import * as _ from "lodash";
import axios from 'axios';
import queryString from 'querystring';
var HttpsProxyAgent = require('https-proxy-agent');
export function Axios(config) {
let auth = 'Basic ' + new Buffer(config.authId + ':' + config.authToken)
.toString('base64');
@ -84,7 +87,25 @@ export function Axios(config) {
});
})
.catch(function (error) {
reject(error.stack+ "\r\n" + JSON.stringify(error.response.data));
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(error));
} else {
if (error.response.status >= 500) {
reject(new Exceptions.ServerError(error));
}
reject(new exceptionClass(error));
}
}
reject(error.stack + '\n' + JSON.stringify(error.response.data));
});
})
}
@ -137,7 +158,7 @@ export function Axios(config) {
}
if (typeof config.proxy !== 'undefined') {
options.proxy = config.proxy;
options.httpsAgent = new HttpsProxyAgent(config.proxy);
}
if (typeof config.timeout !== 'undefined') {
@ -172,7 +193,25 @@ export function Axios(config) {
});
})
.catch(function (error) {
reject(error.stack+ "\r\n" + JSON.stringify(error.response.data));
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(error));
} else {
if (error.response.status >= 500) {
reject(new Exceptions.ServerError(error));
}
reject(new exceptionClass(error));
}
}
reject(error.stack + '\n' + JSON.stringify(error.response.data));
})
}
else {
@ -207,6 +246,24 @@ 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(error));
} else {
if (error.response.status >= 500) {
reject(new Exceptions.ServerError(error));
}
reject(new exceptionClass(error));
}
}
reject(error.stack + '\n' + JSON.stringify(error.response.data));
})
}

View file

@ -1,4 +1,4 @@
export class PlivoRestError extends Error { }
var PlivoRestError = require('./restException');
export class ResourceNotFoundError extends PlivoRestError { }
export class ServerError extends PlivoRestError { }
export class InvalidRequestError extends PlivoRestError { }

View file

@ -0,0 +1,20 @@
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;

View file

@ -59,8 +59,9 @@
},
"dependencies": {
"@types/node": "^14.14.14",
"axios": "^0.19.2",
"axios": "^0.21.1",
"base-64": "^0.1.0",
"https-proxy-agent": "^5.0.0",
"build-url": "^1.0.10",
"form-data": "^4.0.0",
"jsonwebtoken": "^8.5.1",