Skip to content

Commit 1e7cf3b

Browse files
committed
fix(grpc_error): made sure to return 401 in case of errutil.ErrorReasonUnauthorized
Signed-off-by: Mohamed Tahar KEDJOUR <mkedjour@cisco.com>
1 parent 7df02e4 commit 1e7cf3b

3 files changed

Lines changed: 7 additions & 8 deletions

File tree

backend/internal/pkg/grpcutil/errores_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ func TestGrpcError(t *testing.T) {
3535
inErr: errutil.InvalidRequest("c", "c"),
3636
outErr: grpcutil.BadRequestError(errutil.InvalidRequest("c", "c")),
3737
},
38+
"should return unauthorized status error for ErrorReasonUnauthorized": {
39+
inErr: errutil.Unauthorized("d", "d"),
40+
outErr: grpcutil.UnauthorizedError(errutil.Unauthorized("d", "d")),
41+
},
3842
"should return the same error as input when it's not DomainError": {
3943
inErr: generalErr,
4044
outErr: generalErr,

backend/internal/pkg/grpcutil/errors.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ func Error(err error) error {
3939
return BadRequestError(err)
4040
case errutil.ErrorReasonInvalidRequest:
4141
return BadRequestError(err)
42+
case errutil.ErrorReasonUnauthorized:
43+
return UnauthorizedError(err)
4244
}
4345
}
4446

backend/internal/pkg/interceptors/contextual_logger.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,7 @@ import (
1515
"google.golang.org/grpc/metadata"
1616
)
1717

18-
// Enriches logs with identity context (tenantID, userID, etc.)
19-
// and information about the current gRPC request.
20-
//
21-
// It does this by adding a value containing those fields to the context
22-
// and pass it to the next handler, and to include those fields when logging,
23-
// use log.FromContext(ctx).
24-
25-
// Enriches the context with tenant and request metadata for structured logging.
18+
// ContextualLoggerUnary enriches the context with tenant and request metadata for structured logging.
2619
//
2720
// This interceptor extracts tenant related information (such as tenant ID, app ID, etc.) from
2821
// the incoming context, as well as the full gRPC method name and the current request.

0 commit comments

Comments
 (0)