teslainventory_sdk/error.go
2023-08-12 19:45:19 +00:00

26 lines
499 B
Go

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,
)
}