Skip to main content
Glama
global-error-handler.error.ts934 B
import { ArgumentsHost, Catch, ExceptionFilter, HttpException, HttpStatus } from '@nestjs/common'; import { Request, Response } from 'express'; @Catch(Error) export class GlobalExceptionHandler implements ExceptionFilter { catch(exception: Error, host: ArgumentsHost) { const ctx = host.switchToHttp(); const response = ctx.getResponse<Response>() const request = ctx.getRequest<Request>() if (exception instanceof HttpException) { const statusCode = exception.getStatus(); const errorResponse = exception.getResponse(); response .status(statusCode) .json({ statusCode, ...typeof errorResponse === 'string' ? { message: errorResponse } : errorResponse, }); return; } const statusCode = HttpStatus.INTERNAL_SERVER_ERROR let errors = { error: exception.message } response .status(statusCode) .json(errors); } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/RenzoReccio/nestjs-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server