Skip to main content
Glama
errorHandler.ts1.14 kB
import { Request, Response, NextFunction } from 'express'; import logger from '../utils/logger'; export class AppError extends Error { statusCode: number; status: string; isOperational: boolean; constructor(message: string, statusCode: number) { super(message); this.statusCode = statusCode; this.status = `${statusCode}`.startsWith('4') ? 'fail' : 'error'; this.isOperational = true; Error.captureStackTrace(this, this.constructor); } } export const errorHandler = ( err: Error | AppError, req: Request, res: Response, // eslint-disable-next-line @typescript-eslint/no-unused-vars next: NextFunction ) => { if (err instanceof AppError) { logger.error({ message: err.message, statusCode: err.statusCode, stack: err.stack, }); return res.status(err.statusCode).json({ status: err.status, message: err.message, }); } // Programming or other unknown error logger.error({ message: err.message, error: err, stack: err.stack, }); return res.status(500).json({ status: 'error', message: 'Internal server error', }); };

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/visheshd/docmcp'

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