return appropriate error status code in the lock handler (#15950)

This commit is contained in:
Anis Elleuch 2022-10-26 17:51:26 +01:00 committed by GitHub
parent 8dd3c41b2a
commit a35ef155fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -43,7 +43,17 @@ type lockRESTServer struct {
}
func (l *lockRESTServer) writeErrorResponse(w http.ResponseWriter, err error) {
w.WriteHeader(http.StatusForbidden)
statusCode := http.StatusForbidden
switch err {
case errLockNotInitialized:
// Return 425 instead of 5xx, otherwise this node will be marked offline
statusCode = http.StatusTooEarly
case errLockConflict:
statusCode = http.StatusConflict
case errLockNotFound:
statusCode = http.StatusNotFound
}
w.WriteHeader(statusCode)
w.Write([]byte(err.Error()))
}