Created
July 31, 2015 11:33
-
-
Save smashwilson/ef58ea367eede895cdb2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// User code: | |
// "Extract" still has return type "os.GetHeader, err" | |
c, err := containers.Get(client, "foo").Extract() | |
if err != nil { | |
if gophercloud.HasErrorCode(err, gophercloud.ErrNotFound) { | |
// ... | |
} | |
switch gophercloud.ErrorCode(err) { | |
case gophercloud.ErrNotFound: | |
case containers.BadContainerName: | |
} | |
} | |
// Here's a quick sketch of the utility methods in gophercloud: | |
// These are *not* methods on BaseError, because then you'd have to either | |
// return _, gophercloud.BaseError from everything, or make the user cast | |
// all the time. | |
func ErrorCode(err error) CodeType { | |
if casted, ok := err.(BaseError); ok { | |
return casted.Code; | |
} | |
return nil; | |
} | |
func HasErrorCode(err error, code CodeType) bool { | |
return ErrorCode(err) == code; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment