Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: handle object name errors more gracefully #171

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/middleware/r2Middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you link docs to these errors? Maybe ref to the source of Wrangler?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There doesn't appear to be any docs regarding these, opened cloudflare/cloudflare-docs#18098

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
Loading