httpstatus: simplify distribution error status handling
Remove the redundant ErrorCoder type assertion and let the recursive call handle unsupported error types. Make all switch cases return explicitly. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
1 file changed
+4
-5
@@ -117,14 +117,13 @@ func statusCodeFromGRPCError(err error) int {
|
||||
func statusCodeFromDistributionError(err error) int {
|
||||
switch errs := err.(type) {
|
||||
case errcode.Errors:
|
||||
if len(errs) < 1 {
|
||||
return http.StatusInternalServerError
|
||||
}
|
||||
if _, ok := errs[0].(errcode.ErrorCoder); ok {
|
||||
if len(errs) > 0 {
|
||||
return statusCodeFromDistributionError(errs[0])
|
||||
}
|
||||
return http.StatusInternalServerError
|
||||
case errcode.ErrorCoder:
|
||||
return errs.ErrorCode().Descriptor().HTTPStatusCode
|
||||
default:
|
||||
return http.StatusInternalServerError
|
||||
}
|
||||
return http.StatusInternalServerError
|
||||
}
|
||||
Reference in new issue
Block a user