MCPcopy
hub / github.com/jamiepine/voicebox / catchErrorCodes

Function catchErrorCodes

app/src/lib/api/core/request.ts:266–300  ·  view source on GitHub ↗
(options: ApiRequestOptions, result: ApiResult)

Source from the content-addressed store, hash-verified

264};
265
266export const catchErrorCodes = (options: ApiRequestOptions, result: ApiResult): void => {
267 const errors: Record<number, string> = {
268 400: 'Bad Request',
269 401: 'Unauthorized',
270 403: 'Forbidden',
271 404: 'Not Found',
272 500: 'Internal Server Error',
273 502: 'Bad Gateway',
274 503: 'Service Unavailable',
275 ...options.errors,
276 };
277
278 const error = errors[result.status];
279 if (error) {
280 throw new ApiError(options, result, error);
281 }
282
283 if (!result.ok) {
284 const errorStatus = result.status ?? 'unknown';
285 const errorStatusText = result.statusText ?? 'unknown';
286 const errorBody = (() => {
287 try {
288 return JSON.stringify(result.body, null, 2);
289 } catch (e) {
290 return undefined;
291 }
292 })();
293
294 throw new ApiError(
295 options,
296 result,
297 `Generic Error: status: ${errorStatus}; status text: ${errorStatusText}; body: ${errorBody}`,
298 );
299 }
300};
301
302/**
303 * Request method

Callers 1

requestFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected