-
Notifications
You must be signed in to change notification settings - Fork 1
/
internal_error.go
36 lines (30 loc) · 938 Bytes
/
internal_error.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package vhttp
import "fmt"
// InternalError is used to signal that an error returned from a validator
// is not a validation error but an internal error.
//
// An InternalError is meant to wrap a real error returned in the process
// of validating a request or response.
type InternalError struct {
err error
}
// InternalErr creates a new InternalError
func InternalErr(err error) error {
return InternalError{err}
}
func (e InternalError) Error() string {
return e.err.Error()
}
func (e InternalError) Unwrap() error {
return e.err
}
// Wrap returns a new InternalError where the underlying error is the
// result of wrapping e's underlying error (using fmt.Errorf) with
// the message msg prepended to the error message chain.
//
// Equivalent to:
//
// err := vhttp.InternalErr(fmt.Errorf("%s: %w", msg, ierr.Unwrap()))
func (e InternalError) Wrap(msg string) error {
return InternalErr(fmt.Errorf("%s: %w", msg, e.err))
}