Files
calculate_negative_points/internal/utils/error.go
Eugene Howe b0957bfa49
Some checks failed
Docker Build and Publish / publish (push) Failing after 1m33s
webapp
2026-02-17 09:47:30 -05:00

44 lines
871 B
Go

package utils
import (
"net/http"
"github.com/swaggest/rest"
)
// CustomApplicationError is a marker interface that tells error middleware to serialize this error as-is, using Json schema.
type CustomApplicationError interface {
rest.ErrWithHTTPStatus
CustomApplicationError()
}
type ApplicationError struct {
Message string `json:"message"`
code int
}
var (
_ CustomApplicationError = ApplicationError{}
)
func NewApplicationError(message string, code int) ApplicationError {
return ApplicationError{
Message: message,
code: code,
}
}
func (e ApplicationError) Error() string {
return e.Message
}
func (e ApplicationError) HTTPStatus() int {
return e.code
}
func (e ApplicationError) CustomApplicationError() {}
func ValidationError(message string) ApplicationError {
return NewApplicationError(message, http.StatusUnprocessableEntity)
}