Skip to content

Commit

Permalink
improve error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
guyutongxue committed Jan 24, 2025
1 parent 2d6a992 commit bcc6e65
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions api/v2/data/[id].js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,17 @@ export default async function handler(req, res) {
return;
}
if (id.endsWith(".webp")) {
const response = await fetch(
`https://gi-tcg-card-data-img.vercel.app/${id}`,
).then((r) => r.arrayBuffer());
res
.status(200)
.setHeader("Content-Type", "image/webp")
.send(Buffer.from(response));
await fetch(`https://gi-tcg-card-data-img.vercel.app/${id}`)
.then((r) => r.arrayBuffer())
.then((buf) => {
res
.status(200)
.setHeader("Content-Type", "image/webp")
.send(Buffer.from(buf));
})
.catch((err) => {
res.status(502).send({ message: err.message });
});
return;
}
let found;
Expand Down

0 comments on commit bcc6e65

Please sign in to comment.