Skip to content

Commit

Permalink
src: handle object name errors more gracefully (#171)
Browse files Browse the repository at this point in the history
Signed-off-by: flakey5 <[email protected]>
  • Loading branch information
flakey5 authored Nov 11, 2024
1 parent ea15b02 commit bbb7ca7
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/middleware/r2Middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,14 @@ async function getFile(
conditionalHeaders: parseConditionalHeaders(request.headers),
});
} catch (err) {
// Check if R2 threw a range not compatible error
if (err instanceof Error && err.message.includes('10039')) {
return new Response(undefined, { status: 416 });
if (err instanceof Error) {
if (err.message.includes('10020')) {
// Object name not valid, url probably has some weirdness in it
return new Response(undefined, { status: 400 });
} else if (err.message.includes('10039')) {
// Range not compatible, probably out of bounds
return new Response(undefined, { status: 416 });
}
}

ctx.sentry.captureException(err);
Expand Down

0 comments on commit bbb7ca7

Please sign in to comment.