@centure/node-sdk
Version:
A Typescript SDK for interacting with Centure's API
75 lines • 2.69 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.MissingApiKeyError = exports.InternalServerError = exports.PayloadTooLargeError = exports.UnauthorizedError = exports.BadRequestError = exports.CentureApiError = void 0;
const types_1 = require("./types");
/**
* Base error class for Centure API errors
*/
class CentureApiError extends Error {
constructor(message, statusCode, response, requestId) {
super(message);
this.name = "CentureApiError";
this.statusCode = statusCode;
this.response = response;
this.requestId = requestId;
// Maintains proper stack trace for where our error was thrown (only available on V8)
if (Error.captureStackTrace) {
Error.captureStackTrace(this, CentureApiError);
}
}
}
exports.CentureApiError = CentureApiError;
/**
* Error thrown when the request is invalid (400)
*/
class BadRequestError extends CentureApiError {
constructor(message, response, requestId) {
super(message, types_1.HttpStatus.BAD_REQUEST, response, requestId);
this.name = "BadRequestError";
}
}
exports.BadRequestError = BadRequestError;
/**
* Error thrown when authentication fails (401)
*/
class UnauthorizedError extends CentureApiError {
constructor(message, response, requestId) {
super(message, types_1.HttpStatus.UNAUTHORIZED, response, requestId);
this.name = "UnauthorizedError";
}
}
exports.UnauthorizedError = UnauthorizedError;
/**
* Error thrown when the payload is too large (413)
*/
class PayloadTooLargeError extends CentureApiError {
constructor(message, response, requestId) {
super(message, types_1.HttpStatus.PAYLOAD_TOO_LARGE, response, requestId);
this.name = "PayloadTooLargeError";
}
}
exports.PayloadTooLargeError = PayloadTooLargeError;
/**
* Error thrown when the server encounters an error (500)
*/
class InternalServerError extends CentureApiError {
constructor(message, response, requestId) {
super(message, types_1.HttpStatus.INTERNAL_SERVER_ERROR, response, requestId);
this.name = "InternalServerError";
}
}
exports.InternalServerError = InternalServerError;
/**
* Error thrown when the API key is missing
*/
class MissingApiKeyError extends Error {
constructor() {
super("API key is required. Provide it via the constructor or set the CENTURE_API_KEY environment variable.");
this.name = "MissingApiKeyError";
if (Error.captureStackTrace) {
Error.captureStackTrace(this, MissingApiKeyError);
}
}
}
exports.MissingApiKeyError = MissingApiKeyError;
//# sourceMappingURL=errors.js.map