|
@@ -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{
|
|
|
|
- "not found": http.StatusNotFound,
|
|
|
|
- "no such": http.StatusNotFound,
|
|
|
|
- "bad parameter": http.StatusBadRequest,
|
|
|
|
- "no command": http.StatusBadRequest,
|
|
|
|
- "conflict": http.StatusConflict,
|
|
|
|
- "impossible": http.StatusNotAcceptable,
|
|
|
|
- "wrong login/password": http.StatusUnauthorized,
|
|
|
|
- "unauthorized": http.StatusUnauthorized,
|
|
|
|
- "hasn't been activated": http.StatusForbidden,
|
|
|
|
- "this node": http.StatusNotAcceptable,
|
|
|
|
|
|
+ for _, status := range []struct {
|
|
|
|
+ keyword string
|
|
|
|
+ code int
|
|
|
|
+ }{
|
|
|
|
+ {"not found", http.StatusNotFound},
|
|
|
|
+ {"no such", http.StatusNotFound},
|
|
|
|
+ {"bad parameter", http.StatusBadRequest},
|
|
|
|
+ {"no command", http.StatusBadRequest},
|
|
|
|
+ {"conflict", http.StatusConflict},
|
|
|
|
+ {"impossible", 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) {
|
|
|
|
- statusCode = status
|
|
|
|
|
|
+ if strings.Contains(errStr, status.keyword) {
|
|
|
|
+ statusCode = status.code
|
|
break
|
|
break
|
|
}
|
|
}
|
|
}
|
|
}
|