-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Description
Is your feature request related to a problem? Please describe.
I wanted to differentiate errors when using client.Bucket(bktName).Object(objName).Attrs(context.Background()).
Under this method, the following cases all have the same ErrObjectNotExist error:
- non-existent object, OR
- bucket does not exist / user does not have access to the bucket
However, the underlying status code and error message in the original googleapi.Error is actually important to differentiate the two cases above so that we can handle these two errors properly.
Describe the solution you'd like
A way to differentiate the above cases. After some exploration, I was able to differentiate the two cases above by inspecting the raw googleapi.Error error message.
The 1st case (non-existent object) has a 404 statusCode and No such object: .+ error message.
The 2nd case (no access to the bucket) has a 404 statusCode and Not Found error message.
This problem can be solved by one of these solutions:
-
Reduce error abstraction by returning the raw errors instead of
ErrObjectNotExistorErrBucketNotExist
In this solution, I expect that I can extract the actual status code and error message, and perform the necessary error handling mechanism according to the different type of errors. -
Do the error message checks inside Attrs and return the appropriate error based on the actual error message.
In this solution, I expect that Attrs is able to disambiguate between different types of errors and returns the error as eitherErrObjectNotExistorErrBucketNotExistaccording to the actual cause of the error.