@tsed/common
Version:
A TypeScript Framework on top of Express
34 lines • 1.65 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const Exceptions = tslib_1.__importStar(require("@tsed/exceptions"));
const exceptions_1 = require("@tsed/exceptions");
const schema_1 = require("@tsed/schema");
/**
* @ignore
*/
const ErrorSchema = schema_1.object({
name: schema_1.string().required().description("The error name"),
message: schema_1.string().required().description("An error message")
})
.label("GenericError")
.unknown();
schema_1.from(exceptions_1.Exception).properties({
name: schema_1.string().required().description("The error name"),
message: schema_1.string().required().description("An error message"),
status: schema_1.number().required().description("The status code of the exception"),
errors: schema_1.array().items(ErrorSchema).description("A list of related errors"),
stack: schema_1.array().items(schema_1.string()).description("The stack trace (only in development mode)")
});
// Auto load models for all Exceptions
Object.values(Exceptions).forEach((target) => {
if (target !== exceptions_1.Exception && target.STATUS) {
const instance = new target("message");
schema_1.from(target).properties({
name: schema_1.string().required().example(instance.name).default(instance.name).description("The error name"),
status: schema_1.number().required().example(instance.status).default(instance.status).description("The status code of the exception")
});
schema_1.defineStatusModel(target.STATUS, target);
}
});
//# sourceMappingURL=ExceptionSchema.js.map