-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.go
More file actions
41 lines (33 loc) · 1023 Bytes
/
errors.go
File metadata and controls
41 lines (33 loc) · 1023 Bytes
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
package dispatch
import (
"errors"
"net/http"
)
// APIError is an error that contains status code information as well as error text.
type APIError struct {
StatusCode int
ErrorText string
}
// NewAPIErrorFromStatus creates an APIError with text from an HTTP status code.
func NewAPIErrorFromStatus(statusCode int) *APIError {
return &APIError{
StatusCode: statusCode,
ErrorText: http.StatusText(statusCode),
}
}
// NewAPIError returns an APIError from the given HTTP status code and error string.
func NewAPIError(statusCode int, errorText string) *APIError {
return &APIError{
StatusCode: statusCode,
ErrorText: errorText,
}
}
func (apiErr *APIError) Error() string {
return apiErr.ErrorText
}
// ErrBadRequest represents an error from a malformed request.
var ErrBadRequest = errors.New("bad request")
// ErrNotFound represents a 404 error.
var ErrNotFound = errors.New("path not found")
// ErrInternal represents some unexpected internal error.
var ErrInternal = errors.New("internal error")