Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

Commit

Permalink
Return appropriate error for out of range vs syntax
Browse files Browse the repository at this point in the history
Fixes #180
  • Loading branch information
gammazero committed Nov 3, 2023
1 parent 0ef904d commit c21f4fb
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion api/server/handler.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package server

import (
"errors"
"fmt"
"net/http"
"strconv"
Expand Down Expand Up @@ -32,7 +33,11 @@ func (m *HttpServer) handlePostBlob(w http.ResponseWriter, r *http.Request) {
if value := r.Header.Get("Content-Length"); value != "" {
var err error
if contentLength, err = strconv.ParseUint(value, 10, 32); err != nil {
respondWithJson(w, errResponseInvalidContentLength, http.StatusBadRequest)
if errors.Is(err, strconv.ErrSyntax) {
respondWithJson(w, errResponseInvalidContentLength, http.StatusBadRequest)
} else {
respondWithJson(w, errResponseContentLengthTooLarge(m.maxBlobLength), http.StatusBadRequest)
}
return
}
if contentLength > m.maxBlobLength {
Expand Down

0 comments on commit c21f4fb

Please sign in to comment.