1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-24 07:49:41 +02:00

feat(libhttp): move into the Portainer repository EE-5475 (#10231)

This commit is contained in:
andres-portainer 2023-09-01 19:27:02 -03:00 committed by GitHub
parent 090fa4aeb3
commit 8cc5e0796c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
249 changed files with 1059 additions and 639 deletions

View file

@ -0,0 +1,42 @@
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)
}