From 7d253bd4d4f59a91d099e6d29d06b78ba750ff5f Mon Sep 17 00:00:00 2001 From: babaohuang Date: Sat, 16 Dec 2023 10:36:47 +0800 Subject: [PATCH] Update generate.ts --- src/pages/api/generate.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/pages/api/generate.ts b/src/pages/api/generate.ts index 52dd477d..659f1981 100644 --- a/src/pages/api/generate.ts +++ b/src/pages/api/generate.ts @@ -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 }) }