Skip to content

Commit

Permalink
Make storage server properly return 404 on null
Browse files Browse the repository at this point in the history
  • Loading branch information
Aareksio committed Jan 6, 2024
1 parent 293a2a6 commit cc21612
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,25 @@ export function createH3StorageHandler(

const isRaw =
getRequestHeader(event, "accept") === "application/octet-stream";

const checkNull = (value: any) => {
if (value !== null) {
return;
}

throw createError({
statusMessage: "File not found",
statusCode: 404,
});
};

if (isRaw) {
const value = await storage.getItemRaw(key);
checkNull(value);
return value;
} else {
const value = await storage.getItem(key);
checkNull(value);
return stringify(value);
}
}
Expand Down

0 comments on commit cc21612

Please sign in to comment.