This repository has been archived on 2023-04-13. You can view files and clone it, but cannot push or open issues or pull requests.
go-discogs/errors.go

41 lines
877 B
Go
Raw Normal View History

2016-03-09 15:14:42 +00:00
package discogs
import (
"fmt"
)
2016-03-09 15:27:37 +00:00
// APIError represents a Discogs API Error response
2016-03-09 15:14:42 +00:00
type APIError struct {
Message string `json:"message"`
}
2017-04-26 12:57:03 +00:00
// Error ...
2016-03-09 15:14:42 +00:00
func (e APIError) Error() string {
if e.Message != "" {
return fmt.Sprintf("discogs: %v", e.Message)
}
return ""
}
// Empty returns true if empty. Otherwise, at least 1 error message/code is
// present and false is returned.
func (e APIError) Empty() bool {
if e.Message == "" {
return true
}
return false
}
// relevantError returns any non-nil http-related error (creating the request,
// getting the response, decoding) if any. If the decoded apiError is non-zero
// the apiError is returned. Otherwise, no errors occurred, returns nil.
func relevantError(httpError error, apiError APIError) error {
if httpError != nil {
return httpError
}
if apiError.Empty() {
return nil
}
return apiError
}