2017-09-12 11:30:39 -04:00
|
|
|
package oci
|
2017-02-13 05:35:14 -05:00
|
|
|
|
|
|
|
import "fmt"
|
|
|
|
|
|
|
|
// APIError encapsulates an error returned from the API
|
|
|
|
type APIError struct {
|
|
|
|
Code string `json:"code"`
|
|
|
|
Message string `json:"message"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e APIError) Error() string {
|
2017-09-12 11:30:39 -04:00
|
|
|
return fmt.Sprintf("OCI: [%s] '%s'", e.Code, e.Message)
|
2017-02-13 05:35:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// firstError is a helper function to work out which error to return from calls
|
|
|
|
// to the API.
|
|
|
|
func firstError(err error, apiError *APIError) error {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if apiError != nil && len(apiError.Code) > 0 {
|
|
|
|
return apiError
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|