{"modulePath":"github.com/Moranilt/http-utils","version":"v1.1.27","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package tiny_errors\n\n## Functions\n\n```go\nfunc ErrorStorage() map[int]string\n```\nGet global errors storage\n\n```go\nfunc Init(errors map[int]string)\n```\nStore errors globally\n\n## Types\n\n```go\ntype Error struct {\n\tCode    int            `json:\"code\"`\n\tMessage string         `json:\"message\"`\n\tDetails map[string]any `json:\"details\"`\n\t// contains filtered or unexported fields\n}\n```\nDefault type for error data\n\n```go\nfunc (e *Error) Error() string\n```\nError returns the error message.\n\n```go\nfunc (e *Error) FormatMessage(args ...any)\n```\nFormats the message field of the Error using fmt.Sprintf. It replaces any %s and %v specifiers in the message with the provided args.\n\n```go\nfunc (e *Error) GetCode() int\n```\nReturns the code field of the Error.\n\n```go\nfunc (e *Error) GetDetails() map[string]any\n```\nReturns the details map of the Error.\n\n```go\nfunc (e *Error) GetHTTPMessage() string\n```\nReturns the HTTP message associated with the error.\n\n```go\nfunc (e *Error) GetHTTPStatus() int\n```\nReturns the HTTP status code associated with the error.\n\n```go\nfunc (e *Error) GetMessage() string\n```\nReturns the message field of the Error.\n\n```go\nfunc (e *Error) JSON() string\n```\nConverts the Error to a JSON string.\n\n```go\nfunc (e *Error) JSONOrigin() string\n```\nConverts the Error to a JSON string.\n\n```go\nfunc (e *Error) SetCode(code int)\n```\nSets the code field of the Error.\n\n```go\nfunc (e *Error) SetDetail(name, data string)\n```\nAdds a key-value pair to the Details map of the Error. This allows arbitrary additional context to be attached to the Error.\n\n```go\nfunc (e *Error) SetHTTPStatus(code int)\n```\nSets the HTTP status code and message for the error. The status text is looked up from the provided HTTP status code.\n\n```go\nfunc (e *Error) SetMessage(msg string, format ...any)\n```\nSets the message field of the Error, formatting it with fmt.Sprintf if format args are provided.\n\n```go\ntype ErrorHandler interface {\n\tJSON() string\n\tJSONOrigin() string\n\tError() string\n\n\tGetHTTPStatus() int\n\tGetHTTPMessage() string\n\tGetCode() int\n\tGetMessage() string\n\tGetDetails() map[string]any\n}\n```\nErrorHandler defines an interface for handling errors that can be converted to JSON. It includes methods to get the HTTP status, message, error code, error message, and convert the error to JSON.\n\n```go\nfunc New(code int, options ...ErrorOption) ErrorHandler\n```\nCreates a new ErrorHandler with the given error code and options. The code parameter specifies the error code. If a message is registered for the code in ErrorStorage, it will be used as the default message. The options allow configuring additional details like the message, HTTP status, and custom key-value pairs. Returns the configured ErrorHandler.\n\n```go\ntype ErrorOption func(PropertySetter)\n```\nErrorOption is a function type that can be used to configure an Error. It accepts a PropertySetter func to set properties on the Error being constructed.\n\n```go\nfunc Detail(name, data string) ErrorOption\n```\nReturns an ErrorOption that adds a key-value pair to the Details map of the Error being constructed. This allows arbitrary additional context to be attached to the Error.\n\n```go\nfunc HTTPStatus(status int) ErrorOption\n```\nReturns an ErrorOption that sets the HTTPStatus field of the Error being constructed to the provided status code. This allows associating an HTTP status code with the error.\n\n```go\nfunc Message(message string, format ...any) ErrorOption\n```\nReturns an ErrorOption that sets the message field of the Error being constructed, formatting it with fmt.Sprintf if format args are provided.\n\n```go\nfunc MessageArgs(args ...any) ErrorOption\n```\nReturns an ErrorOption that formats the message field of the Error being constructed using fmt.Sprintf, replacing any %s and %v specifiers with the provided args.\n\n```go\ntype PropertySetter interface {\n\tSetMessage(string, ...any)\n\tFormatMessage(...any)\n\tSetCode(int)\n\tSetDetail(name, data string)\n\tSetHTTPStatus(int)\n}\n```\nPropertySetter defines methods to set error properties like message, code, details, and HTTP status. This interface allows abstracting away the specific error implementation.\n\n","path":"github.com/Moranilt/http-utils/tiny_errors","name":"tiny_errors","synopsis":"","isRedistributable":true}
