You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
portainer/pkg/libhttp/error/status.go

43 lines
1008 B

package error
import "net/http"
// HandlerError represents an error raised inside a HTTP handler
type HandlerError struct {
StatusCode int
Message string
Err error
}
func (h *HandlerError) Error() string {
return h.Message
}
func NewError(statusCode int, message string, err error) *HandlerError {
return &HandlerError{
StatusCode: statusCode,
Message: message,
Err: err,
}
}
func BadRequest(message string, err error) *HandlerError {
return NewError(http.StatusBadRequest, message, err)
}
func NotFound(message string, err error) *HandlerError {
return NewError(http.StatusNotFound, message, err)
}
func InternalServerError(message string, err error) *HandlerError {
return NewError(http.StatusInternalServerError, message, err)
}
func Unauthorized(message string, err error) *HandlerError {
return NewError(http.StatusUnauthorized, message, err)
}
func Forbidden(message string, err error) *HandlerError {
return NewError(http.StatusForbidden, message, err)
}