...
1 package apperror
2
3 import "runtime"
4
5
6 var _ StatusCoder = (*StatusError)(nil)
7 var _ Caller = (*StatusError)(nil)
8
9 type StatusError struct {
10 code int
11 err error
12 source SourceLocation
13 }
14
15 func NewStatusError(err error, code int) *StatusError {
16 var location SourceLocation
17 if _, file, line, ok := runtime.Caller(1); ok {
18 location = SourceLocation{File: file, Line: line}
19 }
20
21 return &StatusError{
22 code: code,
23 err: err,
24 source: location,
25 }
26 }
27
28 func (e StatusError) Error() string {
29 return e.err.Error()
30 }
31
32 func (e StatusError) StatusCode() int {
33 return e.code
34 }
35
36 func (e StatusError) Unwrap() error {
37 return e.err
38 }
39
40 func (e StatusError) SourceLocation() SourceLocation {
41 return e.source
42 }
43
View as plain text