UNPKG

@piggly/fastify-chassis

Version:

An ESM/CommonJS toolkit to help you to do common operations in your back-end applications with Fastify and NodeJS.

37 lines 1.49 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.RequestApiServerError = void 0; const crypto_1 = require("crypto"); const ddd_toolkit_1 = require("@piggly/ddd-toolkit"); const events_1 = require("../events/index.js"); /** * @file The error to be thrown when the requested service is unavailable. * @since 5.4.0 * @copyright Piggly Lab 2025 * @author Caique Araujo <caique@piggly.com.br> */ class RequestApiServerError extends ddd_toolkit_1.ApplicationError { /** * Create a new instance of the error. * Useful for: Request API server error and auto publish ApplicationErrorEvent when error is set. * Code: 355204257 * * It will produce a APPLICATION_ERROR_EVENT if there is an error, * when a new object is created. You may listen to it * to setup notifications or actions. * * @param {any} error The error. * @memberof RequestApiServerError * @since 5.4.0 * @author Caique Araujo <caique@piggly.com.br> */ constructor(error) { const hash = (0, crypto_1.randomUUID)(); if (error) { events_1.ApplicationErrorEvent.publish(error, hash); } super('RequestApiServerError', 'Cannot process the request at this moment.', error?.status || 500, `Contact administrator and inform the following code: "${hash}".`, {}, error); } } exports.RequestApiServerError = RequestApiServerError; //# sourceMappingURL=RequestApiServerError.js.map