5 // apiError is an error wrapper that also
6 // holds information about response status codes.
12 // HTTPErrorStatusCode returns a status code.
13 func (e apiError) HTTPErrorStatusCode() int {
17 // NewErrorWithStatusCode allows you to associate
18 // a specific HTTP Status Code to an error.
19 // The server will take that code and set
20 // it as the response status.
21 func NewErrorWithStatusCode(err error, code int) error {
22 return apiError{err, code}
25 // NewBadRequestError creates a new API error
26 // that has the 400 HTTP status code associated to it.
27 func NewBadRequestError(err error) error {
28 return NewErrorWithStatusCode(err, http.StatusBadRequest)
31 // NewRequestForbiddenError creates a new API error
32 // that has the 403 HTTP status code associated to it.
33 func NewRequestForbiddenError(err error) error {
34 return NewErrorWithStatusCode(err, http.StatusForbidden)
37 // NewRequestNotFoundError creates a new API error
38 // that has the 404 HTTP status code associated to it.
39 func NewRequestNotFoundError(err error) error {
40 return NewErrorWithStatusCode(err, http.StatusNotFound)
43 // NewRequestConflictError creates a new API error
44 // that has the 409 HTTP status code associated to it.
45 func NewRequestConflictError(err error) error {
46 return NewErrorWithStatusCode(err, http.StatusConflict)