From 51abe2eaa346c5b714b3b4e0c3bff6d3a9ae4825 Mon Sep 17 00:00:00 2001 From: tako0614 Date: Tue, 16 Jul 2024 00:21:06 +0900 Subject: [PATCH] feat: Add error handling for failed image retrieval in bgimage.ts --- routes/api/v2/client/bgimage.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/routes/api/v2/client/bgimage.ts b/routes/api/v2/client/bgimage.ts index 956c92f3..c020f5af 100644 --- a/routes/api/v2/client/bgimage.ts +++ b/routes/api/v2/client/bgimage.ts @@ -1,10 +1,13 @@ + export const handler = { async GET(req: Request, ctx: any) { - const userid = ctx.state.data.userid; try { // ./backgroundImages/にある画像すべてを取得 const dirPath = "./backgroundImages"; const result = await readRandomImageFromDir(dirPath).catch(console.error); + if(!result) { + return new Response("Internal Server Error", { status: 500 }); + } return new Response(result, { status: 200, headers: { @@ -41,6 +44,4 @@ async function readRandomImageFromDir(dir: string) { const randomFile = `${dir}/${files[randomIndex]}`; const imageData = await Deno.readFile(randomFile); return imageData; - // 画像の内容はバイナリデータとして出力されるため、ここでは内容の表示は省略 - // 必要に応じて画像データを処理するコードを追加してください }