1
0
mirror of https://github.com/imgproxy/imgproxy.git synced 2025-12-23 22:11:10 +02:00
Files
imgproxy/errctx/error.go
Sergei Aleksandrovich e33254005d Refactored errors (#1578)
* Refactored errors

* Make monitoring and errorreport accept `errctx.Error` instead of `error`

* Add server.Error; Remove category from errctx; Make HTTP handlers respond with *server.Error

* Remove stackSkip from errctx.Wrap; Add errctx.WrapWithStackSkip
2025-11-20 01:26:21 +06:00

41 lines
1.3 KiB
Go

package errctx
import "reflect"
// ErrorWithContext is an interface for errors that carry additional context information.
type Error interface {
// Error returns the error message.
Error() string
// StatusCode returns the HTTP status code associated with the error.
StatusCode() int
// PublicMessage returns the public message associated with the error.
PublicMessage() string
// ShouldReport indicates whether the error should be reported.
ShouldReport() bool
// StackTrace returns the stack trace associated with the error.
// This method is traditionally used to retrieve the stack trace
// by packages like error reporters.
StackTrace() []uintptr
// Callers returns the stack trace associated with the error.
// This method is traditionally used to retrieve the stack trace
// by packages like error reporters.
Callers() []uintptr
// FormatStack returns the stack trace as a formatted string.
FormatStack() string
// CloneErrorContext returns a copy of the error context
// with applied options.
CloneErrorContext(opts ...Option) *ErrorContext
}
// ErrorType returns the type name of the given error.
// If the error is [WrappedError], it returns the type of the inner error.
func ErrorType(err error) string {
if ew, ok := err.(*WrappedError); ok {
return ErrorType(ew.Unwrap())
}
return reflect.TypeOf(err).String()
}