UNPKG

@expressots/core

Version:

Expressots - modern, fast, lightweight nodejs web framework (@core)

63 lines (62 loc) 2.71 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Report = void 0; const inversify_1 = require("../di/inversify"); const app_error_1 = require("./app-error"); /** * Report class is a utility class to manage and log errors within the application. * It is responsible for creating a standardized error object, logging it, * and then throwing the error for further handling. */ let Report = class Report { constructor() { this.name = "Report Provider"; this.version = "3.0.0"; this.author = "Richard Zampieri"; this.repo = "https://github.com/expressots/expressots"; } /** * The Error method is responsible for generating a standardized error object, * logging the error, and then throwing it for further handling. * The error thrown is of the custom type AppError, which extends the built-in Error class. * * @param error - An instance of Error or a string that describes the error. * @param statusCode - The HTTP status code associated with the error (default is 500). * @param service - The service name associated with the error. If not specified, * it defaults to the name of the calling function. * * @throws An object of the custom type AppError, which includes details about the error. */ error( // eslint-disable-next-line @typescript-eslint/no-explicit-any error, statusCode, service) { let message = ""; if (error == null) { // error is null or undefined message = ""; } else if (typeof error === "string") { message = error; } else if (error instanceof Error) { message = error.message; } else if (typeof error === "object" && "message" in error) { message = error.message; } else { message = String(error); } return new app_error_1.AppError(message, statusCode, service); } }; exports.Report = Report; exports.Report = Report = __decorate([ (0, inversify_1.injectable)() ], Report);