From a35ef155fc16c806bca713ed9e1f1aa8fd453a48 Mon Sep 17 00:00:00 2001 From: Anis Elleuch Date: Wed, 26 Oct 2022 17:51:26 +0100 Subject: [PATCH] return appropriate error status code in the lock handler (#15950) --- cmd/lock-rest-server.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/cmd/lock-rest-server.go b/cmd/lock-rest-server.go index 43cd3955c..fca50b55b 100644 --- a/cmd/lock-rest-server.go +++ b/cmd/lock-rest-server.go @@ -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())) }