Documentation ¶
Index ¶
- Constants
- Variables
- func AddError(code Code, message string, status int)
- type AlaudaError
- func (h *AlaudaError) AddFieldError(field string, message ...string) *AlaudaError
- func (h *AlaudaError) AddFieldsFromError(format string, index int, err *AlaudaError) *AlaudaError
- func (h *AlaudaError) Error() string
- func (h *AlaudaError) SetCode(code Code) *AlaudaError
- func (h *AlaudaError) SetCodeString(code string) *AlaudaError
- func (h *AlaudaError) SetMessage(format string, args ...interface{}) *AlaudaError
- func (h *AlaudaError) SetSource(source string) *AlaudaError
- type Code
- type StatusMessage
Constants ¶
const ( // ErrorCodeResourceNotFound error when the requested resource was not found ErrorCodeResourceNotFound = "resource_not_exist" // ErrorCodeInvalidArgs error when the request data is incorrect or incomplete ErrorCodeInvalidArgs = "invalid_args" // ErrorCodeBadRequest error when the needed input is not provided ErrorCodeBadRequest = "bad_request" //ErrorCodeResourceAlreadyExists when a resource already exists ErrorCodeResourceAlreadyExists = "resource_already_exist" // ErrorCodeUnknownIssue when the issue is unknown ErrorCodeUnknownIssue = "unknown_issue" // ErrorCodePermissionDenied when user dont have necessary permissions ErrorCodePermissionDenied = "permission_denied" // ErrorCodeResourceStateConflict when the resource is in another state and generates a conflict ErrorCodeResourceStateConflict = "resource_state_conflict" // ErrorCodeNotImplemented when some method is not implemented ErrorCodeNotImplemented = "not_implemented" ErrorCodeUnauthorized = "unauthorized" // ErrorCodeNotFound when is not found ErrorCodeNotFound = "not_found" // ErrorCodeElasticSearchError when using a elastic search and it returned an error ErrorCodeElasticSearchError = "elasticsearch_error" // ErrorCodeDatabaseError when using database commands and it returned an error ErrorCodeDatabaseError = "database_error" )
Variables ¶
var ( // ErrorMessageList general default messages for all error codes ErrorMessageList = map[Code]StatusMessage{ ErrorCodeResourceNotFound: NewErrorStatusMessage("Resource not found", 404), ErrorCodeInvalidArgs: NewErrorStatusMessage("Invalid parameters were passed.", 400), ErrorCodeBadRequest: NewErrorStatusMessage("Required data not valid.", 400), ErrorCodeResourceAlreadyExists: NewErrorStatusMessage("The posted resource already existed.", 400), ErrorCodeUnknownIssue: NewErrorStatusMessage("Unknown issue was caught and message was not specified.", 500), ErrorCodePermissionDenied: NewErrorStatusMessage("Current user has no permission to perform the action.", 403), ErrorCodeResourceStateConflict: NewErrorStatusMessage("The posted resource already existed.", 409), ErrorCodeNotImplemented: NewErrorStatusMessage("Method not implemented", 501), ErrorCodeElasticSearchError: NewErrorStatusMessage("Elastic search error.", 500), ErrorCodeDatabaseError: NewErrorStatusMessage("Database error.", 500), } )
Functions ¶
Types ¶
type AlaudaError ¶
type AlaudaError struct { Source string `json:"source"` Message string `json:"message"` Code Code `json:"code"` Fields []map[string][]string `json:"fields,omitempty"` StatusCode int `json:"-"` }
AlaudaError common error struct used in the whole application
func GetError ¶
func GetError(source string, err *AlaudaError, code Code) *AlaudaError
GetError will create an error or return if already instatiated
func New ¶
func New(source string, code Code) *AlaudaError
New Constructor function for the error structure
func NewCommon ¶
func NewCommon(source string, err error) *AlaudaError
NewCommon return an error from a common error
func TreatError ¶
func TreatError(source string, err error, code string) *AlaudaError
TreatError treat common errors
func (*AlaudaError) AddFieldError ¶
func (h *AlaudaError) AddFieldError(field string, message ...string) *AlaudaError
AddFieldError adds a field error and return itself
func (*AlaudaError) AddFieldsFromError ¶
func (h *AlaudaError) AddFieldsFromError(format string, index int, err *AlaudaError) *AlaudaError
AddFieldsFromError will add the field errors of the given error if any will also add in the current error using a formated string as base
func (*AlaudaError) Error ¶
func (h *AlaudaError) Error() string
Error satisfies the error interface
func (*AlaudaError) SetCode ¶
func (h *AlaudaError) SetCode(code Code) *AlaudaError
SetCode sets a code and returns itself for chaining calls
func (*AlaudaError) SetCodeString ¶
func (h *AlaudaError) SetCodeString(code string) *AlaudaError
SetCodeString sets a code as a string for custom codes
func (*AlaudaError) SetMessage ¶
func (h *AlaudaError) SetMessage(format string, args ...interface{}) *AlaudaError
SetMessage sets a message using the given format and parameters returns itself
func (*AlaudaError) SetSource ¶
func (h *AlaudaError) SetSource(source string) *AlaudaError
SetSource sets the source and returns itself for chaining calls
type StatusMessage ¶
StatusMessage in order to make it simple to keep a list of the used codes and default messages
func NewErrorStatusMessage ¶
func NewErrorStatusMessage(message string, status int) StatusMessage
NewErrorStatusMessage build a message with a status code