mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
526abc00b1
- Return 403 (forbidden) when request is denied in authorization flows (including integration test) - Fix #22428 - Close #22431 Signed-off-by: Liron Levin <liron@twistlock.com>
47 lines
1.4 KiB
Go
47 lines
1.4 KiB
Go
package errors
|
|
|
|
import "net/http"
|
|
|
|
// apiError is an error wrapper that also
|
|
// holds information about response status codes.
|
|
type apiError struct {
|
|
error
|
|
statusCode int
|
|
}
|
|
|
|
// HTTPErrorStatusCode returns a status code.
|
|
func (e apiError) HTTPErrorStatusCode() int {
|
|
return e.statusCode
|
|
}
|
|
|
|
// NewErrorWithStatusCode allows you to associate
|
|
// a specific HTTP Status Code to an error.
|
|
// The Server will take that code and set
|
|
// it as the response status.
|
|
func NewErrorWithStatusCode(err error, code int) error {
|
|
return apiError{err, code}
|
|
}
|
|
|
|
// NewBadRequestError creates a new API error
|
|
// that has the 400 HTTP status code associated to it.
|
|
func NewBadRequestError(err error) error {
|
|
return NewErrorWithStatusCode(err, http.StatusBadRequest)
|
|
}
|
|
|
|
// NewRequestForbiddenError creates a new API error
|
|
// that has the 403 HTTP status code associated to it.
|
|
func NewRequestForbiddenError(err error) error {
|
|
return NewErrorWithStatusCode(err, http.StatusForbidden)
|
|
}
|
|
|
|
// NewRequestNotFoundError creates a new API error
|
|
// that has the 404 HTTP status code associated to it.
|
|
func NewRequestNotFoundError(err error) error {
|
|
return NewErrorWithStatusCode(err, http.StatusNotFound)
|
|
}
|
|
|
|
// NewRequestConflictError creates a new API error
|
|
// that has the 409 HTTP status code associated to it.
|
|
func NewRequestConflictError(err error) error {
|
|
return NewErrorWithStatusCode(err, http.StatusConflict)
|
|
}
|