github.com/mmcquillan/packer@v1.1.1-0.20171009221028-c85cf0483a5d/builder/oracle/oci/client/error.go (about) 1 package oci 2 3 import "fmt" 4 5 // APIError encapsulates an error returned from the API 6 type APIError struct { 7 Code string `json:"code"` 8 Message string `json:"message"` 9 } 10 11 func (e APIError) Error() string { 12 return fmt.Sprintf("OCI: [%s] '%s'", e.Code, e.Message) 13 } 14 15 // firstError is a helper function to work out which error to return from calls 16 // to the API. 17 func firstError(err error, apiError *APIError) error { 18 if err != nil { 19 return err 20 } 21 22 if apiError != nil && len(apiError.Code) > 0 { 23 return apiError 24 } 25 26 return nil 27 }