We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/systeminit/si'
If you have feedback or need assistance with the MCP directory API, please join our Discord server
try-catch.ts•671 B
import isPromise from 'is-promise';
// see https://www.npmjs.com/package/no-try for inspiration
// although their focus was not on the typing...
// this is more about avoiding an explicitly typed `let thing: TypeOfThingFromInsideTry;` above the try/catch scope
/** try-catch alternative that exposes a _typed response_ rather than having it stuck in the try's scope */
export async function tryCatch<T>(
tryFn: () => T | Promise<T>,
catchFn: (e: any) => void | Promise<void>,
): Promise<T | undefined> {
try {
return await tryFn();
} catch (err) {
const catchResult = catchFn(err);
if (isPromise(catchResult)) {
await catchResult;
}
}
}