Documentation ¶
Index ¶
- Constants
- func IsMalformed(err error) bool
- func IsNotFound(err error) bool
- func IsSMTP(err error) bool
- func IsUnretrievable(err error) bool
- func IsWrongType(err error) bool
- func New(msg string) error
- func NewFromResponse(rsp *http.Response) error
- func Newf(msgf string, args ...any) error
- func NewfAt(calldepth int, msgf string, args ...any) error
- func SetMalformed(err error) error
- func SetNotFound(err error) error
- func SetSMTP(err error) error
- func SetUnretrievable(err error) error
- func SetWrongType(err error) error
- func StatusCode(err error) int
- func WithStatusCode(err error, code int) error
- type ErrorType
- type MultiError
- type WithCode
- func NewErrorBadRequest(original error, helpText ...string) WithCode
- func NewErrorClientClosedRequest(original error) WithCode
- func NewErrorConflict(original error, helpText ...string) WithCode
- func NewErrorForbidden(original error, helpText ...string) WithCode
- func NewErrorGone(original error, helpText ...string) WithCode
- func NewErrorInternalError(original error, helpText ...string) WithCode
- func NewErrorNotAcceptable(original error, helpText ...string) WithCode
- func NewErrorNotFound(original error, helpText ...string) WithCode
- func NewErrorRequestTimeout(original error) WithCode
- func NewErrorUnauthorized(original error, helpText ...string) WithCode
- func NewErrorUnprocessableEntity(original error, helpText ...string) WithCode
Constants ¶
const ( StatusClientClosedRequest = 499 StatusTextClientClosedRequest = "Client Closed Request" )
Custom http response codes + text that aren't included in the net/http package.
const Caller = true
Caller returns whether created errors will prepend calling function name.
Variables ¶
This section is empty.
Functions ¶
func IsMalformed ¶ added in v0.13.0
IsMalformed checks error for a stored "malformed" flag. For example an error from an incoming ActivityStreams type conversion.
func IsNotFound ¶ added in v0.13.0
IsNotFound checks error for a stored "not found" flag. For example an error from an outgoing HTTP request due to DNS lookup.
func IsSMTP ¶ added in v0.13.0
IsSMTP checks error for a stored "smtp" flag. For example an error from outgoing SMTP email attempt.
func IsUnretrievable ¶ added in v0.13.0
IsUnretrievable indicates that a call to retrieve a resource (account, status, attachment, etc) could not be fulfilled, either because it was not found locally, or because some prerequisite remote resource call failed, making it impossible to return the item.
func IsWrongType ¶ added in v0.13.0
IsWrongType checks error for a stored "wrong type" flag. Wrong type indicates that an ActivityPub URI returned a type we weren't expecting: Statusable instead of Accountable, or vice versa, for example.
func New ¶ added in v0.10.0
New returns a new error, prepended with caller function name if gtserror.Caller is enabled.
func NewFromResponse ¶ added in v0.10.0
NewResponseError crafts an error from provided HTTP response including the method, status and body (if any provided). This will also wrap the returned error using WithStatusCode() and will include the caller function name as a prefix.
func Newf ¶ added in v0.10.0
Newf returns a new formatted error, prepended with caller function name if gtserror.Caller is enabled.
func NewfAt ¶ added in v0.11.0
NewfAt returns a new formatted error with the given calldepth+1, useful when you want to wrap an error from within an anonymous function or utility function, but preserve the name in the error of the wrapping function that did the calling.
Provide calldepth 2 to prepend only the name of the current containing function, 3 to prepend the name of the function containing *that* function, and so on.
This function is just exposed for dry-dick optimization purposes. Most callers should just call Newf instead.
func SetMalformed ¶ added in v0.13.0
SetMalformed will wrap the given error to store a "malformed" flag, returning wrapped error. See IsMalformed() for example use-cases.
func SetNotFound ¶ added in v0.8.0
SetNotFound will wrap the given error to store a "not found" flag, returning wrapped error. See IsNotFound() for example use-cases.
func SetSMTP ¶ added in v0.13.0
SetSMTP will wrap the given error to store an "smtp" flag, returning wrapped error. See IsSMTP() for example use-cases.
func SetUnretrievable ¶ added in v0.10.0
SetUnretrievable will wrap the given error to store an "unretrievable" flag, returning wrapped error. See Unretrievable() for example use-cases.
func SetWrongType ¶ added in v0.10.0
SetWrongType will wrap the given error to store a "wrong type" flag, returning wrapped error. See IsWrongType() for example use-cases.
func StatusCode ¶ added in v0.8.0
StatusCode checks error for a stored status code value. For example an error from an outgoing HTTP request may be stored, or an API handler expected response status code may be stored.
func WithStatusCode ¶ added in v0.8.0
WithStatusCode will wrap the given error to store provided status code, returning wrapped error. See StatusCode() for example use-cases.
Types ¶
type ErrorType ¶ added in v0.8.0
type ErrorType string
ErrorType denotes the type of an error, if set.
type MultiError ¶ added in v0.7.0
type MultiError []error
MultiError allows encapsulating multiple errors under a singular instance, which is useful when you only want to log on errors, not return early / bubble up.
func NewMultiError ¶ added in v0.11.0
func NewMultiError(capacity int) MultiError
NewMultiError returns a *MultiError with the capacity of its underlying error slice set to the provided value.
This capacity can be exceeded if necessary, but it saves a teeny tiny bit of memory if callers set it correctly.
If you don't know in advance what the capacity must be, just use new(MultiError) instead.
func (*MultiError) Append ¶ added in v0.7.0
func (m *MultiError) Append(err error)
Append the given error to the MultiError.
func (*MultiError) Appendf ¶ added in v0.7.0
func (m *MultiError) Appendf(format string, args ...any)
Append the given format string to the MultiError.
It is valid to use %w in the format string to wrap any other errors.
func (MultiError) Combine ¶ added in v0.7.0
func (m MultiError) Combine() error
Combine the MultiError into a single error.
Unwrap will work on the returned error as expected.
type WithCode ¶
type WithCode interface { // Unwrap returns the original error. // This should *NEVER* be returned to a client as it may contain sensitive information. Unwrap() error // Error serializes the original internal error for debugging within the GoToSocial logs. // This should *NEVER* be returned to a client as it may contain sensitive information. Error() string // Safe returns the API-safe version of the error for serialization towards a client. // There's not much point logging this internally because it won't contain much helpful information. Safe() string // Code returns the status code for serving to a client. Code() int }
WithCode wraps an internal error with an http code, and a 'safe' version of the error that can be served to clients without revealing internal business logic.
A typical use of this error would be to first log the Original error, then return the Safe error and the StatusCode to an API caller.
func NewErrorBadRequest ¶
NewErrorBadRequest returns an ErrorWithCode 400 with the given original error and optional help text.
func NewErrorClientClosedRequest ¶ added in v0.10.0
NewErrorClientClosedRequest returns an ErrorWithCode 499 with the given original error. This error type should only be used when an http caller has already hung up their request. See: https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#nginx
func NewErrorConflict ¶ added in v0.2.0
NewErrorConflict returns an ErrorWithCode 409 with the given original error and optional help text.
func NewErrorForbidden ¶
NewErrorForbidden returns an ErrorWithCode 403 with the given original error and optional help text.
func NewErrorGone ¶ added in v0.6.0
NewErrorGone returns an ErrorWithCode 410 with the given original error and optional help text.
func NewErrorInternalError ¶
NewErrorInternalError returns an ErrorWithCode 500 with the given original error and optional help text.
func NewErrorNotAcceptable ¶ added in v0.3.5
NewErrorNotAcceptable returns an ErrorWithCode 406 with the given original error and optional help text.
func NewErrorNotFound ¶
NewErrorNotFound returns an ErrorWithCode 404 with the given original error and optional help text.
func NewErrorRequestTimeout ¶ added in v0.13.0
NewErrorRequestTimeout returns an ErrorWithCode 408 with the given original error. This error type should only be used when the server has decided to hang up a client request after x amount of time, to avoid keeping extremely slow client requests open.
func NewErrorUnauthorized ¶ added in v0.3.5
NewErrorUnauthorized returns an ErrorWithCode 401 with the given original error and optional help text.
func NewErrorUnprocessableEntity ¶ added in v0.3.5
NewErrorUnprocessableEntity returns an ErrorWithCode 422 with the given original error and optional help text.