Skip to main content
Glama
response-handler.ts1.13 kB
// Helper functions to handle traditional REST response format interface ErrorResponse { error: string; message: string; statusCode: number; nextAction?: string; } export async function handleApiResponse(response: any): Promise<any> { const responseData = await response.json(); // Handle traditional REST format if (!response.ok) { // Error response const errorData = responseData as ErrorResponse; let fullMessage = errorData.message || errorData.error || 'Unknown error'; // Append nextAction if available if (errorData.nextAction) { fullMessage += `. ${errorData.nextAction}`; } throw new Error(fullMessage); } // Success response - data returned directly return responseData; } export function formatSuccessMessage(operation: string, data: any): string { // If data contains a message, use it if (data && typeof data === 'object' && 'message' in data) { return `${data.message}\n${JSON.stringify(data, null, 2)}`; } // Otherwise, create a generic success message return `${operation} completed successfully:\n${JSON.stringify(data, null, 2)}`; }

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/InsForge/insforge-mcp'

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