Skip to main content
Glama
error-handler.test.ts1.83 kB
import { afterEach, beforeEach, describe, expect, it } from 'vitest'; import { createErrorResult } from '@/prompts/error-handler.js'; const TOOL_METADATA = { toolName: 'tests.prompts.circular', userId: 'test-user', requestId: 'test-request', }; describe('prompts/error-handler', () => { const originalNodeEnv = process.env.NODE_ENV; beforeEach(() => { process.env.NODE_ENV = 'development'; }); afterEach(() => { if (originalNodeEnv === undefined) { delete process.env.NODE_ENV; } else { process.env.NODE_ENV = originalNodeEnv; } }); it('omits stack traces from serialized error responses', () => { const internalError = new Error('Internal failure'); internalError.stack = 'Sensitive stack trace that must stay internal'; const clientError = new Error('Safe message'); const result = createErrorResult(clientError, 'Safe message', 500, { logError: internalError, }); const serialized = JSON.stringify(result); expect(serialized).not.toContain('Sensitive stack trace'); expect(result.error.details).toBeDefined(); const sanitizedDetail = result.error.details?.sanitizedDetail; expect(typeof sanitizedDetail).toBe('string'); expect(result.error.message).toBe( 'An internal error occurred while processing the prompt.' ); }); it('serializes circular context without throwing', () => { const circular: Record<string, unknown> & { self?: unknown } = { name: 'circular-context', }; circular.self = circular; const result = createErrorResult( new Error('Circular failure'), 'An error occurred', 500, { ...TOOL_METADATA, context: { payload: circular, }, } ); expect(() => JSON.stringify(result)).not.toThrow(); }); });

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/kesslerio/attio-mcp-server'

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