Created
January 4, 2017 12:46
-
-
Save asm-jaime/0b5a8ca48034cc66a4b15e00021e0925 to your computer and use it in GitHub Desktop.
Easy Api Error
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==================== 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