Skip to content

Instantly share code, notes, and snippets.

@asm-jaime
Created January 4, 2017 12:56
Show Gist options
  • Save asm-jaime/0a65d9675c9fbf9075a3f555660ba5aa to your computer and use it in GitHub Desktop.
Save asm-jaime/0a65d9675c9fbf9075a3f555660ba5aa to your computer and use it in GitHub Desktop.
Processing HTTP API errors
// #################### http error {{{
// ApiHttpError something
type ApiHttpError struct {
Code int `json:"errorCode"`
HttpCode int `json:"-"`
Message string `json:"errorMsg"`
Info string `json:"errorInfo"`
}
func (thisError *ApiHttpError) Error() string {
return thisError.Message
}
func NewApiHttpError(thisError error) *ApiHttpError {
return &ApiHttpError{0, http.StatusInternalServerError, thisError.Error(), ""}
}
var ErrUserPassEmpty = &ApiHttpError{110, http.StatusBadRequest, "Password is empty", ""}
var ErrUserNotFound = &ApiHttpError{123, http.StatusNotFound, "User not found", ""}
var ErrUserIdEmpty = &ApiHttpError{130, http.StatusBadRequest, "Empty User Id", ""}
var ErrUserIdWrong = &ApiHttpError{131, http.StatusBadRequest, "Wrong User Id", ""}
// #################### http error }}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment