@@ -483,13 +483,12 @@ func (r *Repository) Referrers(ctx context.Context, desc ocispec.Descriptor, art
483
483
484
484
// The referrers state is unknown.
485
485
if err != nil {
486
- if ! errors .Is (err , errdef .ErrUnsupported ) {
487
- return err
488
- }
489
- if errutil .IsErrorCode (err , errcode .ErrorCodeNameUnknown ) {
490
- // The repository is not found, no fallback.
491
- return err
486
+ if errors .Is (err , errdef .ErrUnsupported ) {
487
+ // Referrers API is not supported, fallback to referrers tag schema.
488
+ r .SetReferrersCapability (false )
489
+ return r .referrersByTagSchema (ctx , desc , artifactType , fn )
492
490
}
491
+ return err
493
492
// Fallback to referrers tag schema.
494
493
r .SetReferrersCapability (false )
495
494
return r .referrersByTagSchema (ctx , desc , artifactType , fn )
@@ -545,16 +544,19 @@ func (r *Repository) referrersPageByAPI(ctx context.Context, artifactType string
545
544
switch resp .StatusCode {
546
545
case http .StatusOK :
547
546
case http .StatusNotFound :
548
- // A 404 returned by Referrers API indicates that Referrers API is not supported.
549
- return "" , errors .Join (errdef .ErrUnsupported , errutil .ParseErrorResponse (resp ))
547
+ if errResp := errutil .ParseErrorResponse (resp ); errutil .IsErrorCode (errResp , errcode .ErrorCodeNameUnknown ) {
548
+ // The repository is not found, Referrers API status is unknown
549
+ return "" , errResp
550
+ }
551
+ // Referrers API is not supported.
552
+ return "" , fmt .Errorf ("failed to query referrers API: %w" , errdef .ErrUnsupported )
550
553
default :
551
554
return "" , errutil .ParseErrorResponse (resp )
552
555
}
553
556
554
557
// also check the content type
555
558
if ct := resp .Header .Get ("Content-Type" ); ct != ocispec .MediaTypeImageIndex {
556
- err := errors .Join (errdef .ErrUnsupported , errutil .ParseErrorResponse (resp ))
557
- return "" , fmt .Errorf ("unknown content returned (%s), expecting image index: %w" , ct , err )
559
+ return "" , fmt .Errorf ("unknown content returned (%s), expecting image index: %w" , ct , errdef .ErrUnsupported )
558
560
}
559
561
560
562
var index ocispec.Index
0 commit comments