Skip to content

Commit

Permalink
Server-side errors
Browse files Browse the repository at this point in the history
  • Loading branch information
enricoros committed Nov 8, 2023
1 parent 54288bb commit 5d20b63
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/server/api/trpc.serverutils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function createFetcherFromTRPC<TPostBody, TOut>(parser: (response: Response) =>
console.log('-> tRPC', debugGenerateCurlCommand(method, url, headers, body as any));
response = await fetch(url, { method, headers, ...(body !== undefined ? { body: JSON.stringify(body) } : {}) });
} catch (error: any) {
console.error(`[${moduleName} Fetch Error]:`, error);
console.error(`[${moduleName} Error] (fetch):`, error);
throw new TRPCError({
code: 'BAD_REQUEST',
message: `[${moduleName} Issue] (network) ${safeErrorString(error) || 'Unknown fetch error'} - ${error?.cause}`,
Expand All @@ -45,6 +45,7 @@ function createFetcherFromTRPC<TPostBody, TOut>(parser: (response: Response) =>
let error: any | null = await response.json().catch(() => null);
if (error === null)
error = await response.text().catch(() => null);
console.error(`[${moduleName} Error] (upstream):`, response.status, error);
throw new TRPCError({
code: 'BAD_REQUEST',
message: error
Expand All @@ -59,6 +60,7 @@ function createFetcherFromTRPC<TPostBody, TOut>(parser: (response: Response) =>
try {
return await parser(response);
} catch (error: any) {
console.error(`[${moduleName} Error] (parse):`, error);
throw new TRPCError({
code: 'INTERNAL_SERVER_ERROR',
message: `[${moduleName} Issue] (parsing) ${safeErrorString(error) || `Unknown ${parserName} parsing error`}`,
Expand Down

1 comment on commit 5d20b63

@vercel
Copy link

@vercel vercel bot commented on 5d20b63 Nov 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

big-agi – ./

big-agi-enricoros.vercel.app
big-agi-git-main-enricoros.vercel.app
get.big-agi.com

Please sign in to comment.