Skip to content

Commit dfa0635

Browse files
blob/azureblob: refactor error handling and add test recording (#3636)
1 parent f1d2dbc commit dfa0635

File tree

2 files changed

+283
-13
lines changed

2 files changed

+283
-13
lines changed

blob/azureblob/azureblob.go

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -650,25 +650,22 @@ func (b *bucket) ErrorAs(err error, i any) bool {
650650
}
651651

652652
func (b *bucket) ErrorCode(err error) gcerrors.ErrorCode {
653-
if bloberror.HasCode(err, bloberror.BlobNotFound) {
654-
return gcerrors.NotFound
655-
}
656-
if bloberror.HasCode(err, bloberror.AuthenticationFailed) {
657-
return gcerrors.PermissionDenied
658-
}
659653
var rErr *azcore.ResponseError
660654
if errors.As(err, &rErr) {
661-
code := bloberror.Code(rErr.ErrorCode)
662-
if code == bloberror.BlobNotFound || rErr.StatusCode == 404 {
663-
return gcerrors.NotFound
664-
}
665-
if code == bloberror.AuthenticationFailed {
655+
switch bloberror.Code(rErr.ErrorCode) {
656+
case bloberror.AuthenticationFailed:
666657
return gcerrors.PermissionDenied
667-
}
668-
if code == bloberror.BlobAlreadyExists {
658+
case bloberror.BlobAlreadyExists:
669659
return gcerrors.FailedPrecondition
660+
case bloberror.BlobNotFound:
661+
return gcerrors.NotFound
662+
}
663+
664+
if rErr.StatusCode == http.StatusNotFound {
665+
return gcerrors.NotFound
670666
}
671667
}
668+
672669
if strings.Contains(err.Error(), "no such host") {
673670
// This happens with an invalid storage account name; the host
674671
// is something like invalidstorageaccount.blob.core.windows.net.

blob/azureblob/testdata/TestConformance/TestIfNotExist.replay

Lines changed: 273 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)