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

Return a 503 when media uploads fail. #361

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion api/r0/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func UploadMedia(r *http.Request, rctx rcontext.RequestContext, user api.UserInf

rctx.Log.Error("Unexpected error storing media: " + err.Error())
sentry.CaptureException(err)
return api.InternalServerError("Unexpected Error")
return api.ServiceUnavailable()
}

if rctx.Config.Features.MSC2448Blurhash.Enabled && r.URL.Query().Get("xyz.amorgan.generate_blurhash") == "true" {
Expand Down
4 changes: 4 additions & 0 deletions api/responses.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,7 @@ func BadRequest(message string) *ErrorResponse {
func QuotaExceeded() *ErrorResponse {
return &ErrorResponse{common.ErrCodeForbidden, "Quota Exceeded", common.ErrCodeQuotaExceeded}
}

func ServiceUnavailable() *ErrorResponse {
return &ErrorResponse{common.ErrCodeServiceUnavailable, "Service unavailable", common.ErrCodeServiceUnavailable}
}
3 changes: 3 additions & 0 deletions api/webserver/route_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
case common.ErrCodeForbidden:
statusCode = http.StatusForbidden
break
case common.ErrCodeServiceUnavailable:
statusCode = http.StatusServiceUnavailable
break
default: // Treat as unknown (a generic server error)
statusCode = http.StatusInternalServerError
break
Expand Down
1 change: 1 addition & 0 deletions common/errorcodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ const ErrCodeRateLimitExceeded = "M_LIMIT_EXCEEDED"
const ErrCodeUnknown = "M_UNKNOWN"
const ErrCodeForbidden = "M_FORBIDDEN"
const ErrCodeQuotaExceeded = "M_QUOTA_EXCEEDED"
const ErrCodeServiceUnavailable = "M_SERVICE_UNAVAILABLE"