Skip to content

Instantly share code, notes, and snippets.

@smashwilson
Created July 31, 2015 11:33
Show Gist options
  • Save smashwilson/ef58ea367eede895cdb2 to your computer and use it in GitHub Desktop.
Save smashwilson/ef58ea367eede895cdb2 to your computer and use it in GitHub Desktop.
// 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