forked from crewjam/saml
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror.go
More file actions
69 lines (54 loc) · 1.4 KB
/
error.go
File metadata and controls
69 lines (54 loc) · 1.4 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package saml
import (
"fmt"
"net/http"
"github.com/pkg/errors"
)
var (
ErrInvalidRequest = &Error{Code: http.StatusBadRequest}
ErrUnprocessableEntity = &Error{Code: http.StatusUnprocessableEntity}
ErrNotFound = &Error{Code: http.StatusNotFound}
ErrInvalidSAMLRequest = ErrInvalidRequest.WithMessage("Invalid SAML Request")
ErrUnknownServiceProvider = ErrNotFound.WithMessage("Unknown service provider")
ErrUnknownACSEndpoint = ErrNotFound.WithMessage("Unknown ACS endpoint")
)
type Error struct {
Code int
Message string
Err error
}
func (e *Error) WithMessage(msg string) *Error {
ne := *e
ne.Message = msg
return &ne
}
func (e *Error) WithMessagef(msg string, args ...interface{}) *Error {
ne := *e
ne.Message = fmt.Sprintf(msg, args...)
return &ne
}
func (e *Error) Unwrap() error {
return e.Err
}
func (e *Error) Error() string {
if e.Err != nil {
return fmt.Sprintf("%d %s: %s", e.Code, e.Message, e.Err.Error())
}
return fmt.Sprintf("%d %s", e.Code, e.Message)
}
func (e *Error) WithError(err error) *Error {
if e.Err != nil {
err = errors.Wrapf(e.Err, "%s", err)
}
ne := *e
ne.Err = errors.WithStack(err)
return &ne
}
func (e *Error) WithErrorf(err error, msg string, args ...interface{}) *Error {
if e.Err != nil {
err = errors.Wrapf(e.Err, "%s", err)
}
ne := *e
ne.Err = errors.WithStack(errors.Wrapf(err, msg, args...))
return &ne
}