Skip to content

Wrap provider errors with HTTP status code#30

Open
biglittlebigben wants to merge 4 commits into
mainfrom
benjamin/wrap_errors
Open

Wrap provider errors with HTTP status code#30
biglittlebigben wants to merge 4 commits into
mainfrom
benjamin/wrap_errors

Conversation

@biglittlebigben

Copy link
Copy Markdown
Contributor

Summary

  • Add ErrorWithStatusCode type so callers can extract HTTP status codes via errors.As regardless of the storage backend.
  • Wrap returned errors from S3, GCP, Azure, and AliOSS storage operations to expose status codes uniformly.
  • Add unit tests covering nil, native, wrapped, and pass-through cases for each backend.

Motivation

Enables better metrics on upload/download failures by surfacing the HTTP status code in a backend-agnostic way — in particular, distinguishing user errors (4xx: bad credentials, missing object, access denied) from infrastructure issues (5xx, network errors that pass through unwrapped).

Test plan

  • go test ./...

Comment thread error.go Outdated
return fmt.Sprintf("Err: %s, Status Code: %d", e.Err, e.StatusCode)
}

func (e *ErrorWithStatusCode) UnWrap() error {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

should this be Unwrap instead?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

maybe we could add assertion on the wrapped error in tests as well

Comment thread error.go
@@ -0,0 +1,18 @@
package storage

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

license header missing

Comment thread error.go Outdated
}

func (e *ErrorWithStatusCode) Error() string {
return fmt.Sprintf("Err: %s, Status Code: %d", e.Err, e.StatusCode)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit: error stings are usually not capitalized

biglittlebigben and others added 2 commits June 17, 2026 12:30
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants