1
0
mirror of https://github.com/imgproxy/imgproxy.git synced 2025-12-23 22:11:10 +02:00
Files
imgproxy/ierrors/errors.go

56 lines
926 B
Go
Raw Permalink Normal View History

2021-04-26 17:52:50 +06:00
package ierrors
2017-10-05 01:44:58 +06:00
import (
2025-08-01 14:19:50 +02:00
"github.com/imgproxy/imgproxy/v3/errwrap"
2017-10-05 01:44:58 +06:00
)
2025-08-01 14:19:50 +02:00
type Error = errwrap.ErrWrap
type Option func(*Error) *Error
2017-10-05 01:44:58 +06:00
2025-08-01 14:19:50 +02:00
// Now, it's fallback to the original Wrap function
func Wrap(err error, stackSkip int, opts ...Option) *Error {
if err == nil {
return nil
}
var e *Error
2025-08-01 14:19:50 +02:00
x, ok := err.(*Error)
if ok {
e = errwrap.Wrap(x)
} else {
2025-08-01 14:19:50 +02:00
e = errwrap.From(err, stackSkip)
}
for _, opt := range opts {
2025-08-01 14:19:50 +02:00
e = opt(e)
2021-03-22 22:45:37 +06:00
}
return e
2021-03-22 22:45:37 +06:00
}
func WithStatusCode(code int) Option {
2025-08-01 14:19:50 +02:00
return func(e *Error) *Error {
x := e.WithStatusCode(code)
return x
2021-09-29 16:23:54 +06:00
}
}
func WithPublicMessage(msg string) Option {
2025-08-01 14:19:50 +02:00
return func(e *Error) *Error {
return e.WithPublicMessage(msg)
}
2019-08-19 18:05:34 +06:00
}
2017-10-05 01:44:58 +06:00
func WithPrefix(prefix string) Option {
2025-08-01 14:19:50 +02:00
return func(e *Error) *Error {
return errwrap.Wrapf(e, "%s", prefix)
2017-10-05 01:44:58 +06:00
}
}
2017-10-05 01:44:58 +06:00
func WithShouldReport(report bool) Option {
2025-08-01 14:19:50 +02:00
return func(e *Error) *Error {
return e.WithShouldReport(report)
}
}