"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.HttpUserError = exports.HttpInternalServerError = exports.HttpTooManyRequestsError = exports.HttpUnsupportedMediaTypeError = exports.HttpPayloadTooLargeError = exports.HttpConflictError = exports.HttpGoneError = exports.HttpNotFoundError = exports.HttpAccessDeniedError = exports.HttpUnauthorizedError = exports.HttpBadRequestError = exports.HttpError = void 0;
exports.createHttpError = createHttpError;
const tslib_1 = require("tslib");
const _a = tslib_1.__importStar(require("@zyno-io/ts-server-foundation/type-metadata-runtime"));
const __tsf_metadata_type = _a.createCompactMetadataRegistryV1("[1,[{\"kind\":7},{\"kind\":6},{\"kind\":2}]]", []);
let _HttpErrorMetadata_1;
class HttpError extends Error {
    httpCode;
    constructor(httpCode, message) {
        super(message);
        this.httpCode = httpCode;
        this.name = new.target.name;
    }
    static __tsfType = _HttpErrorMetadata_1 = _a.decodeCompactMetadataV1("[1,{\"kind\":16,\"name\":\"HttpError\",\"typeName\":\"HttpError\",\"classType\":{\"$tsf\":0},\"properties\":[],\"methods\":[],\"hasConstructor\":true,\"constructorParameters\":[{\"name\":\"httpCode\",\"type\":{\"$tsfType\":0},\"optional\":false,\"default\":false},{\"name\":\"message\",\"type\":{\"$tsfType\":1},\"optional\":false,\"default\":false}]}]", [() => HttpError], __tsf_metadata_type);
}
exports.HttpError = HttpError;
_HttpErrorMetadata_1.classType = HttpError;
HttpError.__tsfType = _HttpErrorMetadata_1;
let _HttpBadRequestErrorMetadata_1;
class HttpBadRequestError extends HttpError {
    constructor(message = 'Bad Request') {
        super(400, message);
    }
    static __tsfType = _HttpBadRequestErrorMetadata_1 = _a.decodeCompactMetadataV1("[1,{\"kind\":16,\"name\":\"HttpBadRequestError\",\"typeName\":\"HttpBadRequestError\",\"classType\":{\"$tsf\":0},\"properties\":[],\"methods\":[],\"hasConstructor\":true,\"constructorParameters\":[{\"name\":\"message\",\"type\":{\"$tsfType\":2},\"optional\":true,\"default\":true}]}]", [() => HttpBadRequestError], __tsf_metadata_type);
}
exports.HttpBadRequestError = HttpBadRequestError;
_HttpBadRequestErrorMetadata_1.classType = HttpBadRequestError;
HttpBadRequestError.__tsfType = _HttpBadRequestErrorMetadata_1;
let _HttpUnauthorizedErrorMetadata_1;
class HttpUnauthorizedError extends HttpError {
    constructor(message = 'Unauthorized') {
        super(401, message);
    }
    static __tsfType = _HttpUnauthorizedErrorMetadata_1 = _a.decodeCompactMetadataV1("[1,{\"kind\":16,\"name\":\"HttpUnauthorizedError\",\"typeName\":\"HttpUnauthorizedError\",\"classType\":{\"$tsf\":0},\"properties\":[],\"methods\":[],\"hasConstructor\":true,\"constructorParameters\":[{\"name\":\"message\",\"type\":{\"$tsfType\":2},\"optional\":true,\"default\":true}]}]", [() => HttpUnauthorizedError], __tsf_metadata_type);
}
exports.HttpUnauthorizedError = HttpUnauthorizedError;
_HttpUnauthorizedErrorMetadata_1.classType = HttpUnauthorizedError;
HttpUnauthorizedError.__tsfType = _HttpUnauthorizedErrorMetadata_1;
let _HttpAccessDeniedErrorMetadata_1;
class HttpAccessDeniedError extends HttpError {
    constructor(message = 'Access Denied') {
        super(403, message);
    }
    static __tsfType = _HttpAccessDeniedErrorMetadata_1 = _a.decodeCompactMetadataV1("[1,{\"kind\":16,\"name\":\"HttpAccessDeniedError\",\"typeName\":\"HttpAccessDeniedError\",\"classType\":{\"$tsf\":0},\"properties\":[],\"methods\":[],\"hasConstructor\":true,\"constructorParameters\":[{\"name\":\"message\",\"type\":{\"$tsfType\":2},\"optional\":true,\"default\":true}]}]", [() => HttpAccessDeniedError], __tsf_metadata_type);
}
exports.HttpAccessDeniedError = HttpAccessDeniedError;
_HttpAccessDeniedErrorMetadata_1.classType = HttpAccessDeniedError;
HttpAccessDeniedError.__tsfType = _HttpAccessDeniedErrorMetadata_1;
let _HttpNotFoundErrorMetadata_1;
class HttpNotFoundError extends HttpError {
    constructor(message = 'Not Found') {
        super(404, message);
    }
    static __tsfType = _HttpNotFoundErrorMetadata_1 = _a.decodeCompactMetadataV1("[1,{\"kind\":16,\"name\":\"HttpNotFoundError\",\"typeName\":\"HttpNotFoundError\",\"classType\":{\"$tsf\":0},\"properties\":[],\"methods\":[],\"hasConstructor\":true,\"constructorParameters\":[{\"name\":\"message\",\"type\":{\"$tsfType\":2},\"optional\":true,\"default\":true}]}]", [() => HttpNotFoundError], __tsf_metadata_type);
}
exports.HttpNotFoundError = HttpNotFoundError;
_HttpNotFoundErrorMetadata_1.classType = HttpNotFoundError;
HttpNotFoundError.__tsfType = _HttpNotFoundErrorMetadata_1;
let _HttpGoneErrorMetadata_1;
class HttpGoneError extends HttpError {
    constructor(message = 'Gone') {
        super(410, message);
    }
    static __tsfType = _HttpGoneErrorMetadata_1 = _a.decodeCompactMetadataV1("[1,{\"kind\":16,\"name\":\"HttpGoneError\",\"typeName\":\"HttpGoneError\",\"classType\":{\"$tsf\":0},\"properties\":[],\"methods\":[],\"hasConstructor\":true,\"constructorParameters\":[{\"name\":\"message\",\"type\":{\"$tsfType\":2},\"optional\":true,\"default\":true}]}]", [() => HttpGoneError], __tsf_metadata_type);
}
exports.HttpGoneError = HttpGoneError;
_HttpGoneErrorMetadata_1.classType = HttpGoneError;
HttpGoneError.__tsfType = _HttpGoneErrorMetadata_1;
let _HttpConflictErrorMetadata_1;
class HttpConflictError extends HttpError {
    constructor(message = 'Conflict') {
        super(409, message);
    }
    static __tsfType = _HttpConflictErrorMetadata_1 = _a.decodeCompactMetadataV1("[1,{\"kind\":16,\"name\":\"HttpConflictError\",\"typeName\":\"HttpConflictError\",\"classType\":{\"$tsf\":0},\"properties\":[],\"methods\":[],\"hasConstructor\":true,\"constructorParameters\":[{\"name\":\"message\",\"type\":{\"$tsfType\":2},\"optional\":true,\"default\":true}]}]", [() => HttpConflictError], __tsf_metadata_type);
}
exports.HttpConflictError = HttpConflictError;
_HttpConflictErrorMetadata_1.classType = HttpConflictError;
HttpConflictError.__tsfType = _HttpConflictErrorMetadata_1;
let _HttpPayloadTooLargeErrorMetadata_1;
class HttpPayloadTooLargeError extends HttpError {
    constructor(message = 'Payload Too Large') {
        super(413, message);
    }
    static __tsfType = _HttpPayloadTooLargeErrorMetadata_1 = _a.decodeCompactMetadataV1("[1,{\"kind\":16,\"name\":\"HttpPayloadTooLargeError\",\"typeName\":\"HttpPayloadTooLargeError\",\"classType\":{\"$tsf\":0},\"properties\":[],\"methods\":[],\"hasConstructor\":true,\"constructorParameters\":[{\"name\":\"message\",\"type\":{\"$tsfType\":2},\"optional\":true,\"default\":true}]}]", [() => HttpPayloadTooLargeError], __tsf_metadata_type);
}
exports.HttpPayloadTooLargeError = HttpPayloadTooLargeError;
_HttpPayloadTooLargeErrorMetadata_1.classType = HttpPayloadTooLargeError;
HttpPayloadTooLargeError.__tsfType = _HttpPayloadTooLargeErrorMetadata_1;
let _HttpUnsupportedMediaTypeErrorMetadata_1;
class HttpUnsupportedMediaTypeError extends HttpError {
    constructor(message = 'Unsupported Media Type') {
        super(415, message);
    }
    static __tsfType = _HttpUnsupportedMediaTypeErrorMetadata_1 = _a.decodeCompactMetadataV1("[1,{\"kind\":16,\"name\":\"HttpUnsupportedMediaTypeError\",\"typeName\":\"HttpUnsupportedMediaTypeError\",\"classType\":{\"$tsf\":0},\"properties\":[],\"methods\":[],\"hasConstructor\":true,\"constructorParameters\":[{\"name\":\"message\",\"type\":{\"$tsfType\":2},\"optional\":true,\"default\":true}]}]", [() => HttpUnsupportedMediaTypeError], __tsf_metadata_type);
}
exports.HttpUnsupportedMediaTypeError = HttpUnsupportedMediaTypeError;
_HttpUnsupportedMediaTypeErrorMetadata_1.classType = HttpUnsupportedMediaTypeError;
HttpUnsupportedMediaTypeError.__tsfType = _HttpUnsupportedMediaTypeErrorMetadata_1;
let _HttpTooManyRequestsErrorMetadata_1;
class HttpTooManyRequestsError extends HttpError {
    constructor(message = 'Too Many Requests') {
        super(429, message);
    }
    static __tsfType = _HttpTooManyRequestsErrorMetadata_1 = _a.decodeCompactMetadataV1("[1,{\"kind\":16,\"name\":\"HttpTooManyRequestsError\",\"typeName\":\"HttpTooManyRequestsError\",\"classType\":{\"$tsf\":0},\"properties\":[],\"methods\":[],\"hasConstructor\":true,\"constructorParameters\":[{\"name\":\"message\",\"type\":{\"$tsfType\":2},\"optional\":true,\"default\":true}]}]", [() => HttpTooManyRequestsError], __tsf_metadata_type);
}
exports.HttpTooManyRequestsError = HttpTooManyRequestsError;
_HttpTooManyRequestsErrorMetadata_1.classType = HttpTooManyRequestsError;
HttpTooManyRequestsError.__tsfType = _HttpTooManyRequestsErrorMetadata_1;
let _HttpInternalServerErrorMetadata_1;
class HttpInternalServerError extends HttpError {
    constructor(message = 'Internal Server Error') {
        super(500, message);
    }
    static __tsfType = _HttpInternalServerErrorMetadata_1 = _a.decodeCompactMetadataV1("[1,{\"kind\":16,\"name\":\"HttpInternalServerError\",\"typeName\":\"HttpInternalServerError\",\"classType\":{\"$tsf\":0},\"properties\":[],\"methods\":[],\"hasConstructor\":true,\"constructorParameters\":[{\"name\":\"message\",\"type\":{\"$tsfType\":2},\"optional\":true,\"default\":true}]}]", [() => HttpInternalServerError], __tsf_metadata_type);
}
exports.HttpInternalServerError = HttpInternalServerError;
_HttpInternalServerErrorMetadata_1.classType = HttpInternalServerError;
HttpInternalServerError.__tsfType = _HttpInternalServerErrorMetadata_1;
let _HttpUserErrorMetadata_1;
class HttpUserError extends HttpError {
    constructor(message = 'HTTP Error') {
        super(422, message);
    }
    static __tsfType = _HttpUserErrorMetadata_1 = _a.decodeCompactMetadataV1("[1,{\"kind\":16,\"name\":\"HttpUserError\",\"typeName\":\"HttpUserError\",\"classType\":{\"$tsf\":0},\"properties\":[],\"methods\":[],\"hasConstructor\":true,\"constructorParameters\":[{\"name\":\"message\",\"type\":{\"$tsfType\":2},\"optional\":true,\"default\":true}]}]", [() => HttpUserError], __tsf_metadata_type);
}
exports.HttpUserError = HttpUserError;
_HttpUserErrorMetadata_1.classType = HttpUserError;
HttpUserError.__tsfType = _HttpUserErrorMetadata_1;
function createHttpError(httpCode, defaultMessage = defaultHttpMessage(httpCode)) {
    return class extends HttpError {
        constructor(message = defaultMessage) {
            super(httpCode, message);
        }
    };
}
function defaultHttpMessage(httpCode) {
    if (httpCode === 400)
        return 'Bad Request';
    if (httpCode === 401)
        return 'Unauthorized';
    if (httpCode === 403)
        return 'Access Denied';
    if (httpCode === 404)
        return 'Not Found';
    if (httpCode === 409)
        return 'Conflict';
    if (httpCode === 410)
        return 'Gone';
    if (httpCode === 413)
        return 'Payload Too Large';
    if (httpCode === 415)
        return 'Unsupported Media Type';
    if (httpCode === 429)
        return 'Too Many Requests';
    if (httpCode === 500)
        return 'Internal Server Error';
    return 'HTTP Error';
}
//# sourceMappingURL=errors.js.map