expresscheckout-nodejs
Version:
Juspay's official expresscheckout-nodejs sdk
192 lines • 7.35 kB
JavaScript
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
import * as Utils from './utils.js';
var JuspayError = /** @class */ (function (_super) {
__extends(JuspayError, _super);
/**
*
* @param error raw json error response from juspay's api or custom error message, so it's response + message. Default error is Unkown Error
* @param name name of the error optional, default JuspayError
* @returns
*/
function JuspayError(error, http) {
var _this = _super.call(this) || this;
_this.name = 'JuspayError';
_this.httpInfo = http;
Object.setPrototypeOf(_this, JuspayError.prototype);
var defaultErrorMessage = 'Something went wrong, Please check the logs, stacks and messages.';
if (error instanceof Error) {
// for JuspayCryptoError or unexpected error Eg: JSON parser error, Error any other unexpected error
_this.message = error.message;
_this.name = error.name;
return _this;
}
_this.raw = error;
var payload;
if (typeof error == 'string') {
try {
// parse juspay errors for stringified case
_this.message = error;
payload = JSON.parse(error);
}
catch (ignored) {
// actual string, TimeoutError('Connection timeout!!') and Something went wrong cases
_this.message = error;
_this.raw = error;
return _this;
}
}
if (typeof error == 'object') {
payload = error;
}
else {
// internal error
_this.message = new String(error).toString() || defaultErrorMessage;
return _this;
}
if (payload == undefined) {
return _this;
}
_this.status = _this.parseAsString('status', payload);
_this.error_message = _this.parseAsString('error_message', payload);
_this.user_message = _this.parseAsString('user_message', payload);
_this.status = _this.parseAsString('status', payload);
_this.error_code = _this.parseAsString('error_code', payload);
_this.error_info = _this.parseAsObject(payload);
if (_this.error_info && _this.error_info.fields) {
_this.error_info.fields = _this.error_info.fields;
}
if (_this.error_message == undefined) {
try {
_this.message = JSON.stringify(payload);
}
catch (ignored) {
_this.message = defaultErrorMessage;
}
}
else {
if (Utils.isDevEnvironment()) {
_this.message = "".concat(_this.error_message).concat(_this.error_info == undefined
? ''
: ", ".concat(_this.error_info.developer_message));
}
else {
_this.message = _this.error_message;
}
}
return _this;
}
JuspayError.prototype.parseAsObject = function (payload) {
var camelCase = this.snakeToCamel('error_info');
var value = payload['error_info'] || payload[camelCase];
if (typeof value == 'object') {
return JSON.parse(JSON.stringify(value));
}
else if (typeof value == 'string') {
try {
return JSON.parse(value);
}
catch (ignored) {
return undefined;
}
}
else {
return undefined;
}
};
JuspayError.prototype.parseAsString = function (snake_case_string, payload) {
var camelCase = this.snakeToCamel(snake_case_string);
var value = payload[snake_case_string] || payload[camelCase];
if (typeof value == 'string') {
return value;
}
return undefined;
};
JuspayError.prototype.snakeToCamel = function (str) {
return str.replace(/_([a-z])/g, function (match, group) {
return group.toUpperCase();
});
};
return JuspayError;
}(Error));
export { JuspayError };
var APIError = /** @class */ (function (_super) {
__extends(APIError, _super);
function APIError(response) {
var _this = _super.call(this, response) || this;
Object.setPrototypeOf(_this, APIError.prototype);
_this.name = 'ApiError';
return _this;
}
return APIError;
}(JuspayError));
export { APIError };
var TimeoutError = /** @class */ (function (_super) {
__extends(TimeoutError, _super);
function TimeoutError(message) {
var _this = _super.call(this, message || 'Error timeout') || this;
Object.setPrototypeOf(_this, TimeoutError.prototype);
_this.name = 'TimeoutError';
return _this;
}
return TimeoutError;
}(APIError));
export { TimeoutError };
var AuthenticationError = /** @class */ (function (_super) {
__extends(AuthenticationError, _super);
function AuthenticationError(error) {
var _this = _super.call(this, error) || this;
Object.setPrototypeOf(_this, AuthenticationError.prototype);
_this.name = 'AuthenticationError';
return _this;
}
return AuthenticationError;
}(APIError));
export { AuthenticationError };
var AuthorizationError = /** @class */ (function (_super) {
__extends(AuthorizationError, _super);
function AuthorizationError(error) {
var _this = _super.call(this, error) || this;
Object.setPrototypeOf(_this, AuthorizationError.prototype);
_this.name = 'AuthorizationError';
return _this;
}
return AuthorizationError;
}(APIError));
export { AuthorizationError };
var InvalidRequestError = /** @class */ (function (_super) {
__extends(InvalidRequestError, _super);
function InvalidRequestError(error) {
var _this = _super.call(this, error) || this;
Object.setPrototypeOf(_this, InvalidRequestError.prototype);
_this.name = 'InvalidRequestError';
return _this;
}
return InvalidRequestError;
}(APIError));
export { InvalidRequestError };
var InternalServerError = /** @class */ (function (_super) {
__extends(InternalServerError, _super);
function InternalServerError(error) {
var _this = _super.call(this, error || 'Something went wrong.') || this;
Object.setPrototypeOf(_this, InternalServerError.prototype);
_this.name = 'InternalServerError';
return _this;
}
return InternalServerError;
}(APIError));
export { InternalServerError };
//# sourceMappingURL=JuspayError.js.map