Skip to content

Commit

Permalink
switch string to ErrorCode analysis
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Bezzubov <bzz@apache.org>
  • Loading branch information
bzz committed Nov 22, 2018
1 parent 0694920 commit 6709d6a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion daemon/protocol/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (s *protocolServiceServer) InstallDriver(ctx xcontext.Context, req *Install
return nil, status.New(codes.AlreadyExists, err.Error()).Err()
} else if errs, ok := err.(errcode.Errors); ok { //docker err codes analysis
for _, erro := range errs {
if strings.HasPrefix(erro.Error(), "unauthorized") {
if errc, ok := erro.(errcode.Error); ok && errc.ErrorCode() == errcode.ErrorCodeUnauthorized {
return nil, status.New(codes.Unauthenticated, err.Error()).Err()
}
}
Expand Down
5 changes: 4 additions & 1 deletion daemon/protocol/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ type mockedServiceUnauthorizedErr struct {
}

func (s *mockedServiceUnauthorizedErr) InstallDriver(language string, image string, update bool) error {
var errors errcode.Errors = []error{errcode.ErrorCodeDenied, errcode.ErrorCodeUnauthorized}
var errors errcode.Errors = []error{
errcode.Error{Code: errcode.ErrorCodeDenied},
errcode.Error{Code: errcode.ErrorCodeUnauthorized},
}
return errors
}

Expand Down

0 comments on commit 6709d6a

Please sign in to comment.