-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy patherror.go
More file actions
48 lines (38 loc) · 1.03 KB
/
error.go
File metadata and controls
48 lines (38 loc) · 1.03 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
package media
import (
"fmt"
"net/http"
)
///////////////////////////////////////////////////////////////////////////////
// TYPES
type Err uint
///////////////////////////////////////////////////////////////////////////////
// GLOBALS
const (
ErrBadParameter Err = http.StatusBadRequest
ErrInternalError Err = http.StatusInternalServerError
ErrNotImplemented Err = http.StatusNotImplemented
)
///////////////////////////////////////////////////////////////////////////////
// ERROR
func (code Err) Code() uint {
return uint(code)
}
func (code Err) Error() string {
switch code {
case ErrBadParameter:
return "bad parameter"
case ErrInternalError:
return "internal error"
case ErrNotImplemented:
return "not implemented"
default:
return fmt.Sprintf("error code %d", code.Code())
}
}
func (code Err) With(args ...interface{}) error {
return fmt.Errorf("%w: %s", code, fmt.Sprint(args...))
}
func (code Err) Withf(format string, args ...interface{}) error {
return fmt.Errorf("%w: %s", code, fmt.Sprintf(format, args...))
}