mirror of
https://github.com/restic/rest-server.git
synced 2025-10-19 07:33:21 +00:00
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:
parent
d2813ea61b
commit
173bfb5371
2 changed files with 9 additions and 2 deletions
|
@ -75,7 +75,7 @@ func (m *Manager) WrapWriter(req *http.Request, w io.Writer) (io.Writer, int, er
|
|||
if currentSize+contentLen > m.maxRepoSize {
|
||||
err := fmt.Errorf("incoming blob (%d bytes) would exceed maximum size of repository (%d bytes)",
|
||||
contentLen, m.maxRepoSize)
|
||||
return nil, http.StatusRequestEntityTooLarge, err
|
||||
return nil, http.StatusInsufficientStorage, err
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue