-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrors.go
43 lines (36 loc) · 900 Bytes
/
errors.go
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
package dipra
import (
"fmt"
"net/http"
"time"
)
// WrapError for handler error
type WrapError struct {
Code int `json:"code"`
Message interface{} `json:"message"`
Internal string `json:"-"`
Date time.Time `json:"-"`
}
var (
// Err404 for hander 404
Err404 *WrapError = &WrapError{
Code: http.StatusNotFound,
Message: http.StatusText(http.StatusNotFound),
}
// Err405 for hander 405
Err405 *WrapError = &WrapError{
Code: http.StatusMethodNotAllowed,
Message: http.StatusText(http.StatusMethodNotAllowed),
}
// Err500 for hander 500
Err500 *WrapError = &WrapError{
Code: http.StatusMethodNotAllowed,
Message: http.StatusText(http.StatusInternalServerError),
}
)
func (e *WrapError) Error() string {
return fmt.Sprintf("Code : %d, detail : %v", e.Code, e.Message)
}
func (e *WrapError) String() string {
return e.Message.(string)
}