Skip to content

Commit

Permalink
fix: show better internal server error
Browse files Browse the repository at this point in the history
  • Loading branch information
JimmyLv committed Mar 13, 2023
1 parent dda1ef6 commit 62bc2aa
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
10 changes: 7 additions & 3 deletions hooks/useSummarize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import { useToast } from "~/hooks/use-toast";
import { UserConfig, VideoConfig } from "~/lib/types";
import { RATE_LIMIT_COUNT } from "~/utils/constants";

export function useSummarize(showSingIn: (show: boolean) => void, enableStream: boolean = true) {
export function useSummarize(
showSingIn: (show: boolean) => void,
enableStream: boolean = true
) {
const [loading, setLoading] = useState(false);
const [summary, setSummary] = useState<string>("");
const { toast } = useToast();
Expand Down Expand Up @@ -59,11 +62,12 @@ export function useSummarize(showSingIn: (show: boolean) => void, enableStream:
});
showSingIn(true);
} else {
const errorJson = await response.json();
toast({
variant: "destructive",
title: response.statusText,
title: response.status + " " + response.statusText,
// ReadableStream can't get error message
// description: response.body
description: errorJson.errorMessage,
});
}
setLoading(false);
Expand Down
3 changes: 2 additions & 1 deletion lib/openai/fetchOpenAIResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ export async function fetchOpenAIResult(
});

if (res.status !== 200) {
throw new Error("OpenAI API: " + res.statusText);
const errorJson = await res.json();
throw new Error(`OpenAI API Error [${res.statusText}]: ${errorJson.error?.message}`);
}

const { showTimestamp, videoId } = videoConfig;
Expand Down
19 changes: 14 additions & 5 deletions pages/api/sumup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,25 @@ export default async function handler(
userKey,
videoId
);
const result = await fetchOpenAIResult(openAiPayload, openaiApiKey, videoConfig);
const result = await fetchOpenAIResult(
openAiPayload,
openaiApiKey,
videoConfig
);
if (stream) {
return new Response(result);
}

return NextResponse.json(result);
} catch (error: any) {
console.error("API error", error, error.message);
return NextResponse.json({
errorMessage: error.message,
});
console.error(error.message);
return new Response(
JSON.stringify({
errorMessage: error.message,
}),
{
status: 500,
}
);
}
}

1 comment on commit 62bc2aa

@vercel
Copy link

@vercel vercel bot commented on 62bc2aa Mar 13, 2023

Choose a reason for hiding this comment

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

Deployment failed with the following error:

Tried to attach Edge Config ecfg_bpimtz9yfzkggkhjr014d3grn9yj, but it does not exist. Remove or update the EDGE_CONFIG environment variable and try again.

Learn More: https://vercel.com/docs/errors#error-list/invalid-edge-config-connection-string

Please sign in to comment.