Skip to content

Commit f76f63e

Browse files
author
Nils L. Hillmann
committed
Use switch instead of subsequent if statements
Have a default for unknown errorcodes.
1 parent 394def7 commit f76f63e

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

routers/user/oauth.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -632,13 +632,15 @@ func handleAuthorizeError(ctx *context.Context, authErr AuthorizeError, redirect
632632

633633
func handleBearerTokenError(ctx *context.Context, beErr BearerTokenError) {
634634
ctx.Resp.Header().Set("WWW-Authenticate", fmt.Sprintf("Bearer realm=\"\", error=\"%s\", error_description=\"%s\"", beErr.ErrorCode, beErr.ErrorDescription))
635-
if beErr.ErrorCode == BearerTokenErrorCodeInvalidRequest {
635+
switch beErr.ErrorCode {
636+
case BearerTokenErrorCodeInvalidRequest:
636637
ctx.JSON(http.StatusBadRequest, beErr)
637-
}
638-
if beErr.ErrorCode == BearerTokenErrorCodeInvalidToken {
638+
case BearerTokenErrorCodeInvalidToken:
639639
ctx.JSON(http.StatusUnauthorized, beErr)
640-
}
641-
if beErr.ErrorCode == BearerTokenErrorCodeInsufficientScope {
640+
case BearerTokenErrorCodeInsufficientScope:
642641
ctx.JSON(http.StatusForbidden, beErr)
642+
default:
643+
log.Error("Invalid BearerTokenErrorCode: %v", beErr.ErrorCode)
644+
ctx.ServerError("Unhandled BearerTokenError", fmt.Errorf("BearerTokenError: error=\"%v\", error_description=\"%v\"", beErr.ErrorCode, beErr.ErrorDescription))
643645
}
644646
}

0 commit comments

Comments
 (0)