-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patherror.go
More file actions
48 lines (38 loc) · 727 Bytes
/
Copy patherror.go
File metadata and controls
48 lines (38 loc) · 727 Bytes
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
package goherence
import (
"fmt"
"net/http"
)
type Error struct {
Message string
Cause error
Status int
}
func wrapError(msg string, cause error, status int) *Error {
if cause == nil {
return nil
}
return newError(msg, cause, status)
}
func newError(msg string, cause error, status int) *Error {
return &Error{
Message: msg,
Cause: cause,
Status: status,
}
}
func (err *Error) Unwrap() error {
return err.Cause
}
func (err *Error) Error() string {
if err.Cause != nil {
return fmt.Sprintf("%s: %s", err.Message, err.Cause)
}
return err.Message
}
func (err *Error) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if err == nil {
return
}
http.Error(w, err.Error(), err.Status)
}