mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #28530 from stevvooe/derandom-error-codes
api/server/httputils: ensure consistent status code
This commit is contained in:
commit
e93bd7b8ce
1 changed files with 16 additions and 13 deletions
|
@ -49,20 +49,23 @@ func GetHTTPErrorStatusCode(err error) int {
|
||||||
// If we need to differentiate between different possible error types,
|
// If we need to differentiate between different possible error types,
|
||||||
// we should create appropriate error types that implement the httpStatusError interface.
|
// we should create appropriate error types that implement the httpStatusError interface.
|
||||||
errStr := strings.ToLower(errMsg)
|
errStr := strings.ToLower(errMsg)
|
||||||
for keyword, status := range map[string]int{
|
for _, status := range []struct {
|
||||||
"not found": http.StatusNotFound,
|
keyword string
|
||||||
"no such": http.StatusNotFound,
|
code int
|
||||||
"bad parameter": http.StatusBadRequest,
|
}{
|
||||||
"no command": http.StatusBadRequest,
|
{"not found", http.StatusNotFound},
|
||||||
"conflict": http.StatusConflict,
|
{"no such", http.StatusNotFound},
|
||||||
"impossible": http.StatusNotAcceptable,
|
{"bad parameter", http.StatusBadRequest},
|
||||||
"wrong login/password": http.StatusUnauthorized,
|
{"no command", http.StatusBadRequest},
|
||||||
"unauthorized": http.StatusUnauthorized,
|
{"conflict", http.StatusConflict},
|
||||||
"hasn't been activated": http.StatusForbidden,
|
{"impossible", http.StatusNotAcceptable},
|
||||||
"this node": http.StatusNotAcceptable,
|
{"wrong login/password", http.StatusUnauthorized},
|
||||||
|
{"unauthorized", http.StatusUnauthorized},
|
||||||
|
{"hasn't been activated", http.StatusForbidden},
|
||||||
|
{"this node", http.StatusNotAcceptable},
|
||||||
} {
|
} {
|
||||||
if strings.Contains(errStr, keyword) {
|
if strings.Contains(errStr, status.keyword) {
|
||||||
statusCode = status
|
statusCode = status.code
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue