Skip to content

Commit 16b4b1e

Browse files
authored
[public-api] Correctly map 401 to Unathenticated (#16711)
1 parent 2ff2d88 commit 16b4b1e

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

components/public-api-server/pkg/proxy/errors.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func categorizeRPCError(err error) *connect.Error {
3333
return connect.NewError(connect.CodeInvalidArgument, fmt.Errorf(rpcErr.Message))
3434
// components/gitpod-protocol/src/messaging/error.ts
3535
case 401:
36-
return connect.NewError(connect.CodePermissionDenied, fmt.Errorf(rpcErr.Message))
36+
return connect.NewError(connect.CodeUnauthenticated, fmt.Errorf(rpcErr.Message))
3737
// components/gitpod-protocol/src/messaging/error.ts
3838
case 403:
3939
return connect.NewError(connect.CodePermissionDenied, fmt.Errorf(rpcErr.Message))

components/public-api-server/pkg/proxy/errors_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ func TestConvertError(t *testing.T) {
3434
},
3535
ExpectedError: connect.NewError(connect.CodeInvalidArgument, fmt.Errorf("user id is a required argument")),
3636
},
37+
{
38+
Input: &jsonrpc2.Error{
39+
Code: 401,
40+
Message: "user is not authenticated",
41+
},
42+
ExpectedError: connect.NewError(connect.CodeUnauthenticated, fmt.Errorf("user is not authenticated")),
43+
},
3744
{
3845
Input: &jsonrpc2.Error{
3946
Code: -32603,

0 commit comments

Comments
 (0)