@@ -23,33 +23,29 @@ func translateRegistryError(ctx context.Context, err error) error {
2323 var derrs docker.Errors
2424 if ! errors .As (err , & derrs ) {
2525 var remoteErr remoteerrors.ErrUnexpectedStatus
26+ var derr docker.Error
2627 if errors .As (err , & remoteErr ) {
2728 if jerr := json .Unmarshal (remoteErr .Body , & derrs ); jerr != nil {
2829 log .G (ctx ).WithError (derrs ).Debug ("unable to unmarshal registry error" )
2930 return fmt .Errorf ("%w: %w" , cerrdefs .ErrUnknown , err )
3031 }
31- if len (derrs ) == 0 {
32- if remoteErr .StatusCode == http .StatusUnauthorized || remoteErr .StatusCode == http .StatusForbidden {
33- // Some registries or token servers may use an old deprecated error format
34- // which only has a "details" field and not the OCI defined "errors" array.
35- var tokenErr struct {
36- Details string `json:"details"`
37- }
38- if jerr := json .Unmarshal (remoteErr .Body , & tokenErr ); jerr == nil && tokenErr .Details != "" {
39- if remoteErr .StatusCode == http .StatusUnauthorized {
40- return cerrdefs .ErrUnauthenticated .WithMessage (fmt .Sprintf ("%s - %s" , docker .ErrorCodeUnauthorized .Message (), tokenErr .Details ))
41- }
42- return cerrdefs .ErrPermissionDenied .WithMessage (fmt .Sprintf ("%s - %s" , docker .ErrorCodeDenied .Message (), tokenErr .Details ))
32+ if len (derrs ) == 0 && (remoteErr .StatusCode == http .StatusUnauthorized || remoteErr .StatusCode == http .StatusForbidden ) {
33+ // Some registries or token servers may use an old deprecated error format
34+ // which only has a "details" field and not the OCI defined "errors" array.
35+ var tokenErr struct {
36+ Details string `json:"details"`
37+ }
38+ if jerr := json .Unmarshal (remoteErr .Body , & tokenErr ); jerr == nil && tokenErr .Details != "" {
39+ if remoteErr .StatusCode == http .StatusUnauthorized {
40+ return cerrdefs .ErrUnauthenticated .WithMessage (fmt .Sprintf ("%s - %s" , docker .ErrorCodeUnauthorized .Message (), tokenErr .Details ))
4341 }
42+ return cerrdefs .ErrPermissionDenied .WithMessage (fmt .Sprintf ("%s - %s" , docker .ErrorCodeDenied .Message (), tokenErr .Details ))
4443 }
4544 }
45+ } else if errors .As (err , & derr ) {
46+ derrs = append (derrs , derr )
4647 } else {
47- var derr docker.Error
48- if errors .As (err , & derr ) {
49- derrs = append (derrs , derr )
50- } else {
51- return err
52- }
48+ return err
5349 }
5450 }
5551 var errs []error
0 commit comments