UNPKG

tempnumber-client

Version:

temp-number.org SMS Typescript client

124 lines (123 loc) 4.57 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.InternalException = exports.ServiceUnavailableException = exports.ResourceBadStateException = exports.ResourceNotFoundException = exports.InvalidRequestParamsException = exports.TooManyRequestsException = exports.UnauthorizedException = exports.Exception = void 0; class Exception extends Error { constructor(parentError, message, status = 500) { super(message); /** * Set error message */ Object.defineProperty(this, 'parentError', { configurable: true, enumerable: false, value: parentError, writable: true }); /** * Set error message */ Object.defineProperty(this, 'message', { configurable: true, enumerable: false, value: message, writable: true }); /** * Set error name as a public property */ Object.defineProperty(this, 'name', { configurable: true, enumerable: false, value: this.constructor.name, writable: true }); /** * Set status as a public property */ Object.defineProperty(this, 'status', { configurable: true, enumerable: false, value: status, writable: true }); /** * Update the stack trace */ Error.captureStackTrace(this, this.constructor); } } exports.Exception = Exception; class UnauthorizedException extends Exception { constructor(parentError, message, status) { message = message || 'Unauthorized to access this resource'; status = status || 401; super(parentError, message, status); } } exports.UnauthorizedException = UnauthorizedException; class TooManyRequestsException extends Exception { constructor(parentError, message, status) { message = message || 'Too Many Requests'; status = status || 429; super(parentError, message, status); this.xRateLimitLimit = null; // Maximum allowed number of requests. this.xRateLimitRemaining = null; // Remaining allowed number of requests. this.xRateLimitReset = null; //Unix timestamp when the rate limit will reset. this.retryAfter = null; // Number of seconds to wait before retrying the request. } setHeader(response) { if (response['x-ratelimit-limit']) { this.xRateLimitLimit = parseInt(response['x-ratelimit-limit']); } if (response['x-ratelimit-remaining']) { this.xRateLimitRemaining = parseInt(response['x-ratelimit-remaining']); } if (response['x-ratelimit-reset']) { this.xRateLimitReset = parseInt(response['x-ratelimit-reset']); } if (response['retry-after']) { this.retryAfter = parseInt(response['retry-after']); } } } exports.TooManyRequestsException = TooManyRequestsException; class InvalidRequestParamsException extends Exception { constructor(parentError, message, status) { message = message || 'Invalid request params'; status = status || 400; super(parentError, message, status); } } exports.InvalidRequestParamsException = InvalidRequestParamsException; class ResourceNotFoundException extends Exception { constructor(parentError, message, status) { message = message || 'Resource not found'; status = status || 404; super(parentError, message, status); } } exports.ResourceNotFoundException = ResourceNotFoundException; class ResourceBadStateException extends Exception { constructor(parentError, message, status) { message = message || 'Resource is in a bad state'; status = status || 409; super(parentError, message, status); } } exports.ResourceBadStateException = ResourceBadStateException; class ServiceUnavailableException extends Exception { constructor(parentError, message, status) { message = message || 'Service Unavailable'; status = status || 503; super(parentError, message, status); } } exports.ServiceUnavailableException = ServiceUnavailableException; class InternalException extends Exception { constructor(parentError, message, status) { message = message || 'Internal Error'; status = status || 500; super(parentError, message, status); } } exports.InternalException = InternalException;