orb-billing
Version:
The official TypeScript library for the Orb API
294 lines • 12 kB
JavaScript
"use strict";
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
Object.defineProperty(exports, "__esModule", { value: true });
exports.OrbInternalServerError = exports.TooManyRequests = exports.ResourceTooLarge = exports.RequestTooLarge = exports.ResourceConflict = exports.URLNotFound = exports.ResourceNotFound = exports.OrbAuthenticationError = exports.RequestValidationError = exports.FeatureNotAvailable = exports.DuplicateResourceCreation = exports.ConstraintViolation = exports.InternalServerError = exports.RateLimitError = exports.UnprocessableEntityError = exports.ConflictError = exports.NotFoundError = exports.PermissionDeniedError = exports.AuthenticationError = exports.BadRequestError = exports.APIConnectionTimeoutError = exports.APIConnectionError = exports.APIUserAbortError = exports.APIError = exports.OrbError = void 0;
const core_1 = require("./core.js");
class OrbError extends Error {
}
exports.OrbError = OrbError;
class APIError extends OrbError {
constructor(status, error, message, headers) {
super(`${APIError.makeMessage(status, error, message)}`);
this.status = status;
this.headers = headers;
this.error = error;
}
static makeMessage(status, error, message) {
const msg = error?.message ?
typeof error.message === 'string' ?
error.message
: JSON.stringify(error.message)
: error ? JSON.stringify(error)
: message;
if (status && msg) {
return `${status} ${msg}`;
}
if (status) {
return `${status} status code (no body)`;
}
if (msg) {
return msg;
}
return '(no status code or body)';
}
static generate(status, errorResponse, message, headers) {
if (!status || !headers) {
return new APIConnectionError({ message, cause: (0, core_1.castToError)(errorResponse) });
}
const error = errorResponse;
const type = error?.['type'];
if (type === 'https://docs.withorb.com/reference/error-responses#400-constraint-violation' &&
status === 400) {
return new ConstraintViolation(status, error, message, headers);
}
if (type === 'https://docs.withorb.com/reference/error-responses#400-duplicate-resource-creation' &&
status === 400) {
return new DuplicateResourceCreation(status, error, message, headers);
}
if (type === 'https://docs.withorb.com/reference/error-responses#404-feature-not-available' &&
status === 400) {
return new FeatureNotAvailable(status, error, message, headers);
}
if (type === 'https://docs.withorb.com/reference/error-responses#400-request-validation-errors' &&
status === 400) {
return new RequestValidationError(status, error, message, headers);
}
if (type === 'https://docs.withorb.com/reference/error-responses#401-authentication-error' &&
status === 401) {
return new OrbAuthenticationError(status, error, message, headers);
}
if (type === 'https://docs.withorb.com/reference/error-responses#404-resource-not-found' &&
status === 404) {
return new ResourceNotFound(status, error, message, headers);
}
if (type === 'https://docs.withorb.com/reference/error-responses#404-url-not-found' && status === 404) {
return new URLNotFound(status, error, message, headers);
}
if (type === 'https://docs.withorb.com/reference/error-responses#409-resource-conflict' &&
status === 409) {
return new ResourceConflict(status, error, message, headers);
}
if (type === 'https://docs.withorb.com/reference/error-responses#413-request-too-large' &&
status === 413) {
return new RequestTooLarge(status, error, message, headers);
}
if (type === 'https://docs.withorb.com/reference/error-responses#413-resource-too-large' &&
status === 413) {
return new ResourceTooLarge(status, error, message, headers);
}
if (type === 'https://docs.withorb.com/reference/error-responses#429-too-many-requests' &&
status === 429) {
return new TooManyRequests(status, error, message, headers);
}
if (type === 'https://docs.withorb.com/reference/error-responses#500-internal-server-error' &&
status === 500) {
return new OrbInternalServerError(status, error, message, headers);
}
if (status === 400) {
return new BadRequestError(status, error, message, headers);
}
if (status === 401) {
return new AuthenticationError(status, error, message, headers);
}
if (status === 403) {
return new PermissionDeniedError(status, error, message, headers);
}
if (status === 404) {
return new NotFoundError(status, error, message, headers);
}
if (status === 409) {
return new ConflictError(status, error, message, headers);
}
if (status === 422) {
return new UnprocessableEntityError(status, error, message, headers);
}
if (status === 429) {
return new RateLimitError(status, error, message, headers);
}
if (status >= 500) {
return new InternalServerError(status, error, message, headers);
}
return new APIError(status, error, message, headers);
}
}
exports.APIError = APIError;
class APIUserAbortError extends APIError {
constructor({ message } = {}) {
super(undefined, undefined, message || 'Request was aborted.', undefined);
}
}
exports.APIUserAbortError = APIUserAbortError;
class APIConnectionError extends APIError {
constructor({ message, cause }) {
super(undefined, undefined, message || 'Connection error.', undefined);
// in some environments the 'cause' property is already declared
// @ts-ignore
if (cause)
this.cause = cause;
}
}
exports.APIConnectionError = APIConnectionError;
class APIConnectionTimeoutError extends APIConnectionError {
constructor({ message } = {}) {
super({ message: message ?? 'Request timed out.' });
}
}
exports.APIConnectionTimeoutError = APIConnectionTimeoutError;
class BadRequestError extends APIError {
}
exports.BadRequestError = BadRequestError;
class AuthenticationError extends APIError {
}
exports.AuthenticationError = AuthenticationError;
class PermissionDeniedError extends APIError {
}
exports.PermissionDeniedError = PermissionDeniedError;
class NotFoundError extends APIError {
}
exports.NotFoundError = NotFoundError;
class ConflictError extends APIError {
}
exports.ConflictError = ConflictError;
class UnprocessableEntityError extends APIError {
}
exports.UnprocessableEntityError = UnprocessableEntityError;
class RateLimitError extends APIError {
}
exports.RateLimitError = RateLimitError;
class InternalServerError extends APIError {
}
exports.InternalServerError = InternalServerError;
class ConstraintViolation extends BadRequestError {
constructor(status, error, message, headers) {
const data = error;
super(status, error, message, headers);
this.status = data?.['status'];
this.type = data?.['type'];
this.detail = data?.['detail'];
this.title = data?.['title'];
}
}
exports.ConstraintViolation = ConstraintViolation;
class DuplicateResourceCreation extends BadRequestError {
constructor(status, error, message, headers) {
const data = error;
super(status, error, message, headers);
this.status = data?.['status'];
this.type = data?.['type'];
this.detail = data?.['detail'];
this.title = data?.['title'];
}
}
exports.DuplicateResourceCreation = DuplicateResourceCreation;
class FeatureNotAvailable extends BadRequestError {
constructor(status, error, message, headers) {
const data = error;
super(status, error, message, headers);
this.status = data?.['status'];
this.type = data?.['type'];
this.detail = data?.['detail'];
this.title = data?.['title'];
}
}
exports.FeatureNotAvailable = FeatureNotAvailable;
class RequestValidationError extends BadRequestError {
constructor(status, error, message, headers) {
const data = error;
super(status, error, message, headers);
this.status = data?.['status'];
this.type = data?.['type'];
this.validation_errors = data?.['validation_errors'] ?? [];
this.detail = data?.['detail'];
this.title = data?.['title'];
}
}
exports.RequestValidationError = RequestValidationError;
class OrbAuthenticationError extends AuthenticationError {
constructor(status, error, message, headers) {
const data = error;
super(status, error, message, headers);
this.status = data?.['status'];
this.type = data?.['type'];
this.detail = data?.['detail'];
this.title = data?.['title'];
}
}
exports.OrbAuthenticationError = OrbAuthenticationError;
class ResourceNotFound extends NotFoundError {
constructor(status, error, message, headers) {
const data = error;
super(status, error, message, headers);
this.status = data?.['status'];
this.title = data?.['title'];
this.type = data?.['type'];
this.detail = data?.['detail'];
}
}
exports.ResourceNotFound = ResourceNotFound;
class URLNotFound extends NotFoundError {
constructor(status, error, message, headers) {
const data = error;
super(status, error, message, headers);
this.status = data?.['status'];
this.type = data?.['type'];
this.detail = data?.['detail'];
this.title = data?.['title'];
}
}
exports.URLNotFound = URLNotFound;
class ResourceConflict extends ConflictError {
constructor(status, error, message, headers) {
const data = error;
super(status, error, message, headers);
this.status = data?.['status'];
this.type = data?.['type'];
this.detail = data?.['detail'];
this.title = data?.['title'];
}
}
exports.ResourceConflict = ResourceConflict;
class RequestTooLarge extends APIError {
constructor(status, error, message, headers) {
const data = error;
super(status, error, message, headers);
this.status = data?.['status'];
this.type = data?.['type'];
this.detail = data?.['detail'];
this.title = data?.['title'];
}
}
exports.RequestTooLarge = RequestTooLarge;
class ResourceTooLarge extends APIError {
constructor(status, error, message, headers) {
const data = error;
super(status, error, message, headers);
this.status = data?.['status'];
this.type = data?.['type'];
this.detail = data?.['detail'];
this.title = data?.['title'];
}
}
exports.ResourceTooLarge = ResourceTooLarge;
class TooManyRequests extends RateLimitError {
constructor(status, error, message, headers) {
const data = error;
super(status, error, message, headers);
this.status = data?.['status'];
this.type = data?.['type'];
this.detail = data?.['detail'];
this.title = data?.['title'];
}
}
exports.TooManyRequests = TooManyRequests;
class OrbInternalServerError extends InternalServerError {
constructor(status, error, message, headers) {
const data = error;
super(status, error, message, headers);
this.status = data?.['status'];
this.type = data?.['type'];
this.detail = data?.['detail'];
this.title = data?.['title'];
}
}
exports.OrbInternalServerError = OrbInternalServerError;
//# sourceMappingURL=error.js.map