UNPKG

@seratch_/bolt-fastify

Version:
55 lines 2.76 kB
"use strict"; // The arguments for the dispatchErrorHandler, Object.defineProperty(exports, "__esModule", { value: true }); exports.defaultUnhandledRequestHandler = exports.defaultProcessEventErrorHandler = exports.defaultDispatchErrorHandler = void 0; const bolt_1 = require("@slack/bolt"); // The default dispathErrorHandler implementation: // Developers can customize this behavior by passing dispatchErrorHandler to the constructor // Note that it was not possible to make this function async due to the limitation of http module function defaultDispatchErrorHandler(args) { const { error, logger, request, response } = args; if ('code' in error) { if (error.code === bolt_1.ErrorCode.HTTPReceiverDeferredRequestError) { logger.info(`Unhandled HTTP request (${request.method}) made to ${request.url}`); response.writeHead(404); response.end(); return; } } logger.error(`An unexpected error occurred during a request (${request.method}) made to ${request.url}`); logger.debug(`Error details: ${error}`); response.writeHead(500); response.end(); } exports.defaultDispatchErrorHandler = defaultDispatchErrorHandler; // The default processEventErrorHandler implementation: // Developers can customize this behavior by passing processEventErrorHandler to the constructor async function defaultProcessEventErrorHandler(args) { const { error, response, logger, storedResponse } = args; if ('code' in error) { // CodedError has code: string const errorCode = error.code; if (errorCode === bolt_1.ErrorCode.AuthorizationError) { // authorize function threw an exception, which means there is no valid installation data response.writeHead(401); response.end(); return true; } } logger.error('An unhandled error occurred while Bolt processed an event'); logger.debug(`Error details: ${error}, storedResponse: ${storedResponse}`); response.writeHead(500); response.end(); return false; } exports.defaultProcessEventErrorHandler = defaultProcessEventErrorHandler; // The default unhandledRequestHandler implementation: // Developers can customize this behavior by passing unhandledRequestHandler to the constructor // Note that this method cannot be an async function to align with the implementation using setTimeout function defaultUnhandledRequestHandler(args) { const { logger } = args; logger.error('An incoming event was not acknowledged within 3 seconds. ' + 'Ensure that the ack() argument is called in a listener.'); } exports.defaultUnhandledRequestHandler = defaultUnhandledRequestHandler; //# sourceMappingURL=receiver-error-handlers.js.map