Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sundowndev
GitHub Repository: sundowndev/phoneinfoga
Path: blob/master/web/errors/errors.go
988 views
1
package errors
2
3
import (
4
"errors"
5
"net/http"
6
)
7
8
type Error struct {
9
status int
10
err error
11
}
12
13
func (e *Error) Status() int {
14
return e.status
15
}
16
17
func (e *Error) Error() error {
18
return e.err
19
}
20
21
func (e *Error) String() string {
22
if e.err == nil {
23
return "unknown error"
24
}
25
return e.err.Error()
26
}
27
28
func NewBadRequest(err error) *Error {
29
if err == nil {
30
err = errors.New("bad request")
31
}
32
return &Error{
33
status: http.StatusBadRequest,
34
err: err,
35
}
36
}
37
38
func NewInternalError(err error) *Error {
39
if err == nil {
40
err = errors.New("internal error")
41
}
42
return &Error{
43
status: http.StatusInternalServerError,
44
err: err,
45
}
46
}
47
48