Skip to content

Commit

Permalink
feat: preserve auth errors in cloudrunner.WrapTransient
Browse files Browse the repository at this point in the history
Currently when wrapping errors containing codes `Unauthenticated` and
`PermissionDenied` they're wrapped in `codes.Internal`. These are both
client errors that should be communicated.

Check for these codes and preserve them.
  • Loading branch information
Anders Jansson committed Nov 10, 2021
1 parent 8042d8b commit d62a6a3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion clouderror/wrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func WrapTransient(err error, msg string) error {
func WrapTransientCaller(err error, msg string, caller Caller) error {
if s, ok := status.FromError(err); ok {
switch s.Code() {
case codes.Unavailable, codes.DeadlineExceeded, codes.Canceled:
case codes.Unavailable, codes.DeadlineExceeded, codes.Canceled, codes.Unauthenticated, codes.PermissionDenied:
return &wrappedStatusError{status: status.New(s.Code(), msg), err: err, caller: caller}
}
}
Expand Down
10 changes: 10 additions & 0 deletions clouderror/wrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ func Test_WrapTransient(t *testing.T) {
err: status.Error(codes.Unavailable, "transient"),
expectedCode: codes.Unavailable,
},
{
name: "codes.Unauthenticated",
err: status.Error(codes.Unauthenticated, "transient"),
expectedCode: codes.Unauthenticated,
},
{
name: "codes.PermissionDenied",
err: status.Error(codes.PermissionDenied, "transient"),
expectedCode: codes.PermissionDenied,
},
{
name: "wrapped transient",
err: Wrap(
Expand Down

0 comments on commit d62a6a3

Please sign in to comment.