import { UpstreamServiceError } from '@dotcom-reliability-kit/errors/lib'; /** * Class that wraps the standard Error */ class BaseError extends Error { public data = {}; /** * Enhance message with data * @param message Message of the error * @param data Supporting information */ constructor(message: string, data?: any) { super(message); this.data = data; } /** * Return the error name with the error message * @returns formatted error */ toString() { const dataString = JSON.stringify(this.data, null, 2); return `${this.constructor.name}: ${this.message}\n\n${dataString}`; } } /** * HTTP response code 400 received from API */ class BadRequestError extends BaseError {} /** * HTTP response code 401 received from API */ class UnauthorizedError extends BaseError {} /** * HTTP response code 402 received from API */ class PaymentRequiredError extends BaseError {} /** * HTTP response code 403 received from API */ class ForbiddenError extends BaseError {} /** * HTTP response code 404 received from API */ class NotFoundError extends BaseError {} /** * HTTP response code in 500 range received from API */ class ServerError extends BaseError {} /** * Response from the API was invalid */ class InvalidResponseError extends BaseError {} /** * No result to return after processing */ class EmptyResultError extends BaseError {} /** * Incorrect parameter supplied */ class ValidationError extends BaseError {} /** * Membership returned a 200 response with errors in body */ class Status200Error extends BaseError {} export { UpstreamServiceError, NotFoundError, BadRequestError, UnauthorizedError, PaymentRequiredError, ForbiddenError, ServerError, InvalidResponseError, EmptyResultError, ValidationError, Status200Error };