Documentation ¶
Index ¶
- Constants
- func ErrorCode(err error) string
- func ErrorMessage(err error) string
- func ErrorOp(err error) string
- func WithErrorCode(code string) func(*Error)
- func WithErrorErr(err error) func(*Error)
- func WithErrorMsg(msg string) func(*Error)
- func WithErrorOp(op string) func(*Error)
- type ChronografError
- type Error
- type HTTPErrorHandler
Constants ¶
const ( EInternal = "internal error" ENotImplemented = "not implemented" ENotFound = "not found" EConflict = "conflict" // action cannot be performed EInvalid = "invalid" // validation failed EUnprocessableEntity = "unprocessable entity" // data type is correct, but out of range EEmptyValue = "empty value" EForbidden = "forbidden" ETooManyRequests = "too many requests" EMethodNotAllowed = "method not allowed" ETooLarge = "request too large" )
Some error code constant, ideally we want define common platform codes here projects on use platform's error, should have their own central place like this. Any time this set of constants changes, you must also update the swagger for Error.properties.code.enum.
Variables ¶
This section is empty.
Functions ¶
func ErrorCode ¶
ErrorCode returns the code of the root error, if available; otherwise returns EINTERNAL.
func ErrorMessage ¶
ErrorMessage returns the human-readable message of the error, if available. Otherwise returns a generic error message.
func WithErrorCode ¶
WithErrorCode sets the code on the error.
func WithErrorErr ¶
WithErrorErr sets the err on the error.
func WithErrorMsg ¶
WithErrorMsg sets the message on the error.
func WithErrorOp ¶
WithErrorOp sets the message on the error.
Types ¶
type ChronografError ¶
type ChronografError string
ChronografError is a domain error encountered while processing chronograf requests.
func (ChronografError) Error ¶
func (e ChronografError) Error() string
ChronografError returns the string of an error.
type Error ¶
Error is the error struct of platform.
Errors may have error codes, human-readable messages, and a logical stack trace.
The Code targets automated handlers so that recovery can occur. Msg is used by the system operator to help diagnose and fix the problem. Op and Err chain errors together in a logical stack trace to further help operators.
To create a simple error,
&Error{ Code:ENotFound, }
To show where the error happens, add Op.
&Error{ Code: ENotFound, Op: "bolt.FindUserByID" }
To show an error with a unpredictable value, add the value in Msg.
&Error{ Code: EConflict, Message: fmt.Sprintf("organization with name %s already exist", aName), }
To show an error wrapped with another error.
&Error{ Code:EInternal, Err: err, }.
func (*Error) MarshalJSON ¶
MarshalJSON recursively marshals the stack of Err.
func (*Error) UnmarshalJSON ¶
UnmarshalJSON recursively unmarshals the error stack.
type HTTPErrorHandler ¶
type HTTPErrorHandler interface {
HandleHTTPError(ctx context.Context, err error, w http.ResponseWriter)
}
HTTPErrorHandler is the interface to handle http error.