Skip to content

Commit

Permalink
Added Error Message Catching
Browse files Browse the repository at this point in the history
  • Loading branch information
Type-32 committed Feb 28, 2024
1 parent 63bf16d commit 8f99cb6
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"locales.title": "Locales",
"locales.en": "English",
"locales.cn": "Chinese",
"main.response.error": "An error occurred while generating a response. Please refresh the page. If this issue persists, please contact the site admin.",
"main.response.error": "An error occurred while generating a response. Please refresh the page. If this issue persists, please contact the site admin.\nError: ",
"docs.coming_soon": "Coming Soon...",
"main.check_docs.1": "Want to use it in your own project?",
"main.check_docs.2": "Check out our docs!",
Expand Down
2 changes: 1 addition & 1 deletion locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"locales.title": "语言",
"locales.en": "英语",
"locales.cn": "中文",
"main.response.error": "哦不!在生成回复时遇到一个错误。请刷新该网页;若该问题持续发生,请联系站点管理员。",
"main.response.error": "哦不!在生成回复时遇到一个错误。请刷新该网页;若该问题持续发生,请联系站点管理员。\n错误信息: ",
"docs.coming_soon": "敬请等待...",
"main.check_docs.1": "想要在你自己的项目中使用吗?",
"main.check_docs.2": "来看看我们的文档吧!",
Expand Down
2 changes: 1 addition & 1 deletion nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default defineNuxtConfig({
},
runtimeConfig: {
apiRateLimit: 50, // Default: 50 requests per min
apiWindowDuration: 15, // Default: 15 minutes
apiWindowDuration: 2, // Default: 2 minutes
openaiApiKey: '',
public:{
apiModel: 'gpt-3.5-turbo',
Expand Down
7 changes: 4 additions & 3 deletions pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ async function stream(){
if (!completion) {
activeResponse.value = "errorMessage"
generatingResponse.value = awaitingResponse.value = false;
throw new Error()
throw new Error("Completion response is null.")
}
if (completion.status != 200) throw new Error()
if (completion.status != 200) throw new Error(`${completion.status} ${completion.statusText}`)
awaitingResponse.value = false;
activeResponse.value = "Loading..."
Expand Down Expand Up @@ -105,6 +105,7 @@ async function stream(){
messages.value.push({role: 'assistant', content: activeResponse.value})
} catch (e: any) {
errorOccurred.value = true;
activeResponse.value = e?.message;
}
awaitingResponse.value = generatingResponse.value = false;
Expand Down Expand Up @@ -157,7 +158,7 @@ onBeforeMount(() => {
<!-- <ChatBubble role="assistant" :message="$t('main.response.error')" :loading="awaitingResponse" :generating="generatingResponse" :error="errorOccurred" v-if="errorOccurred"/>-->
<div role="alert" class="alert alert-error" v-if="errorOccurred">
<svg xmlns="http://www.w3.org/2000/svg" class="stroke-current shrink-0 h-6 w-6" fill="none" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z" /></svg>
<span>{{ $t('main.response.error') }}</span>
<span>{{ `${$t('main.response.error')}${activeResponse}` }}</span>
</div>
</div>
</div>
Expand Down
8 changes: 4 additions & 4 deletions server/api/v1/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ interface Message {
export default defineEventHandler(async (event) => {
// console.log(process.env)

// throw createError({
// status: 400,
// message: 'An unknown error occurred while fetching stream response'
// })
throw createError({
status: 400,
message: 'An unknown error occurred while fetching stream response'
})

// It is not suggested here to change the system prompt.
let messages: Message[] = [{ role: "system", content: "You instructions in response to the user's prompt (format your response in markdown for better readability for the user, and also respond in the user's prompted language.):\n" +
Expand Down

0 comments on commit 8f99cb6

Please sign in to comment.