зеркало из https://github.com/microsoft/docker.git
refactor httpError() and add 404 "not found" mapping
When docker pull a non-existent repo, daemon will report "image xxx not found" with an error code 500, which should be 404. This commit add 404 "not found" mapping and refactor httpError function. Signed-off-by: Zhang Wei <zhangwei555@huawei.com>
This commit is contained in:
Родитель
fdc5aa2043
Коммит
ab42a3a23a
|
@ -203,18 +203,19 @@ func httpError(w http.ResponseWriter, err error) {
|
|||
// If we need to differentiate between different possible error types, we should
|
||||
// create appropriate error types with clearly defined meaning.
|
||||
errStr := strings.ToLower(err.Error())
|
||||
if strings.Contains(errStr, "no such") {
|
||||
statusCode = http.StatusNotFound
|
||||
} else if strings.Contains(errStr, "bad parameter") {
|
||||
statusCode = http.StatusBadRequest
|
||||
} else if strings.Contains(errStr, "conflict") {
|
||||
statusCode = http.StatusConflict
|
||||
} else if strings.Contains(errStr, "impossible") {
|
||||
statusCode = http.StatusNotAcceptable
|
||||
} else if strings.Contains(errStr, "wrong login/password") {
|
||||
statusCode = http.StatusUnauthorized
|
||||
} else if strings.Contains(errStr, "hasn't been activated") {
|
||||
statusCode = http.StatusForbidden
|
||||
for keyword, status := range map[string]int{
|
||||
"not found": http.StatusNotFound,
|
||||
"no such": http.StatusNotFound,
|
||||
"bad parameter": http.StatusBadRequest,
|
||||
"conflict": http.StatusConflict,
|
||||
"impossible": http.StatusNotAcceptable,
|
||||
"wrong login/password": http.StatusUnauthorized,
|
||||
"hasn't been activated": http.StatusForbidden,
|
||||
} {
|
||||
if strings.Contains(errStr, keyword) {
|
||||
statusCode = status
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
logrus.WithFields(logrus.Fields{"statusCode": statusCode, "err": err}).Error("HTTP Error")
|
||||
|
|
Загрузка…
Ссылка в новой задаче