teslainventory_sdk/error.go

26 lines
499 B
Go
Raw Permalink Normal View History

package teslainventory_sdk
import "fmt"
// APIError represent an API error.
type APIError struct {
StatusCode int `json:"-"`
Message string `json:"error"`
}
// Error satisfy the error interface.
func (a APIError) Error() string {
if a.Message != "" {
return fmt.Sprintf(
"HTTP response failed with status code %d, error message: %s",
a.StatusCode,
a.Message,
)
}
return fmt.Sprintf(
"HTTP response failed with status code %d and no error message",
a.StatusCode,
)
}