Reply "insufficient storage" on disk full or over-quota

This commit will change the current behavior on disk-related errors:
* HTTP 507 "Insufficient storage" is the status on disk full or
over-quota
* HTTP 500 "Internal server error" on other disk-related errors
previously both were 400 "Bad request"
This commit is contained in:
Enrico204 2021-08-21 13:43:51 +02:00
parent d2813ea61b
commit 173bfb5371
2 changed files with 9 additions and 2 deletions

View file

@ -4,6 +4,7 @@ import (
"crypto/sha256"
"encoding/hex"
"encoding/json"
"errors"
"fmt"
"io"
"io/ioutil"
@ -14,6 +15,7 @@ import (
"regexp"
"runtime"
"strings"
"syscall"
"time"
"github.com/miolini/datacounter"
@ -603,7 +605,12 @@ func (h *Handler) saveBlob(w http.ResponseWriter, r *http.Request) {
if h.opt.Debug {
log.Print(err)
}
httpDefaultError(w, http.StatusBadRequest)
var pathError *os.PathError
if errors.As(err, &pathError) && (pathError.Err == syscall.ENOSPC || pathError.Err == syscall.EDQUOT) {
httpDefaultError(w, http.StatusInsufficientStorage)
} else {
httpDefaultError(w, http.StatusInternalServerError)
}
return
}