-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhttp.go
36 lines (28 loc) · 827 Bytes
/
http.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
package panicea
import (
"fmt"
"net/http"
)
type HttpError struct {
StatusCode int
Cause error
}
func (e *HttpError) Error() string {
return fmt.Sprintf("status=%d, %s", e.StatusCode, e.Cause.Error())
}
func new(code int, err error, args ...interface{}) *HttpError {
fmsg := args[0].(string)
return &HttpError{code, fmt.Errorf(fmsg, err)}
}
func Unauthorized(err error, args ...interface{}) error {
return new(http.StatusUnauthorized, err, args...)
}
func BadRequest(err error, args ...interface{}) error {
return new(http.StatusBadRequest, err, args...)
}
func ServiceUnavailable(err error, args ...interface{}) error {
return new(http.StatusServiceUnavailable, err, args...)
}
func InternalServerError(err error, args ...interface{}) error {
return new(http.StatusInternalServerError, err, args...)
}