UNPKG

glitchkit

Version:

A lightweight toolkit to create and manage expressive, structured, and reusable error types. Perfect for APIs, services, and glitchy adventures

63 lines (62 loc) 1.8 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const GlitchKitBaseError_1 = __importDefault(require("./GlitchKitBaseError")); class GlitchKitBaseHttpError extends GlitchKitBaseError_1.default { constructor(message, statusCode, errorCode) { super(message, errorCode); this._statusCode = statusCode; Object.setPrototypeOf(this, GlitchKitBaseHttpError.prototype); Error.captureStackTrace(this, this.constructor); } static isInstance(error) { return error instanceof GlitchKitBaseHttpError; } get statusCode() { return this._statusCode; } set statusCode(value) { this._statusCode = value; } withStatusCode(statusCode) { this._statusCode = statusCode; return this; } get url() { return this._url; } set url(value) { this._url = value; } withUrl(url) { this._url = url; return this; } get request() { return this._request; } set request(value) { this._request = value; } withRequest(request) { this._request = request; return this; } get response() { return this._response; } set response(value) { this._response = value; } withResponse(response) { this._response = response; return this; } toJSON() { const jsonError = Object.assign(Object.assign({}, super.toJSON()), { statusCode: this._statusCode, url: this._url, request: this._request, response: this._response }); return jsonError; } } exports.default = GlitchKitBaseHttpError;