Skip to content

Commit

Permalink
Update generate.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
babaohuang committed Dec 16, 2023
1 parent 141ca9b commit 7d253bd
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/pages/api/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,16 @@ export const post: APIRoute = async(context) => {
return new Response(responseStream, { status: 200, headers: { 'Content-Type': 'text/plain; charset=utf-8' } })
} catch (error) {
console.error(error)
const errorMessage = error.message
const regex = /https?:\/\/[^\s]+/g
const filteredMessage = errorMessage.replace(regex, '').trim()
const messageParts = filteredMessage.split('[400 Bad Request]')
const cleanMessage = messageParts.length > 1 ? messageParts[1].trim() : filteredMessage

return new Response(JSON.stringify({
error: {
code: error.name,
message: cleanMessage,
},
}), { status: 500 })
}
Expand Down

1 comment on commit 7d253bd

@vercel
Copy link

@vercel vercel bot commented on 7d253bd Dec 16, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.