Skip to content

Instantly share code, notes, and snippets.

@asm-jaime
Created January 4, 2017 12:46
Show Gist options
  • Save asm-jaime/0b5a8ca48034cc66a4b15e00021e0925 to your computer and use it in GitHub Desktop.
Save asm-jaime/0b5a8ca48034cc66a4b15e00021e0925 to your computer and use it in GitHub Desktop.
Easy Api Error
// ==================== easy error {{{
type EasyAPIError struct {
Errors []ErrorDetail `json:"errors"`
}
// ErrorDetail represents an individual item in an EasyAPIError.
type ErrorDetail struct {
Message string `json:"message"`
Code int `json:"code"`
}
func NewEasyApiError(code int, message string) *ErrorDetail {
return &ErrorDetail{
Message: message,
Code: code,
}
}
func (thisError EasyAPIError) Error() string {
if len(thisError.Errors) > 0 {
err := thisError.Errors[0]
return fmt.Sprintf("twitter: %d %v", err.Code, err.Message)
}
return ""
}
// Empty returns true if empty. Otherwise, at least 1 error message/code is
// present and false is returned.
func (thisError EasyAPIError) Empty() bool {
if len(thisError.Errors) == 0 {
return true
}
return false
}
// ==================== }}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment