Skip to content

src: handle r2 errors in R2Middleware - #1071

Open
flakey5 wants to merge 1 commit into
mainfrom
flakey5/1069
Open

flakey5 wants to merge 1 commit into
mainfrom
flakey5/1069

Conversation

@flakey5

@flakey5 flakey5 commented Oct 25, 2026

Copy link
Copy Markdown
Member

Following #1067 we should be explicitly returning a 500 when we exhaust R2 retries now

Fixes #1069

Following #1067 we should be explicitly returning a 500 when we exhaust
R2 retries now

Fixes #1069

Signed-off-by: flakey5 <[email protected]>
@flakey5
flakey5 requested a review from a team as a code owner October 25, 2026 18:18
if (err instanceof Error) {
// Error object likely from R2, let's handle it here

if (err.message.includes('10020')) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should these error codes be in a constant with @ref to the r2 documentation (if these errors are even documented)

* @returns <T> if fn didn't throw, a {@link Reponse} otherwise
* @throws anything that's thrown by fn and isn't an error
*/
async function wrapR2Call<T>(fn: () => Promise<T>): Promise<T | Response> {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could the method name be maybe more descriptive?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also could the type not be a generic T, maybe extend something that is an actual R2 call/method signature?

@ovflowd ovflowd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

SGTM, left some nits!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error: reached the end of middleware

2 participants