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:
Sebastiaan van Stijn committed 2026-11-04 16:05:45 +01:00
1 parent 5df4160942
commit 7ec2f1d2d3
1 file changed
+4 -5
+4 -5
View File
@@ -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
}