github.com/akerouanton/docker@v1.11.0-rc3/errors/errors.go (about) 1 package errors 2 3 import "net/http" 4 5 // apiError is an error wrapper that also 6 // holds information about response status codes. 7 type apiError struct { 8 error 9 statusCode int 10 } 11 12 // HTTPErrorStatusCode returns a status code. 13 func (e apiError) HTTPErrorStatusCode() int { 14 return e.statusCode 15 } 16 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} 23 } 24 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) 29 } 30 31 // NewRequestNotFoundError creates a new API error 32 // that has the 404 HTTP status code associated to it. 33 func NewRequestNotFoundError(err error) error { 34 return NewErrorWithStatusCode(err, http.StatusNotFound) 35 } 36 37 // NewRequestConflictError creates a new API error 38 // that has the 409 HTTP status code associated to it. 39 func NewRequestConflictError(err error) error { 40 return NewErrorWithStatusCode(err, http.StatusConflict) 41 }