Files
hanko/backend/dto/errors.go
2022-06-09 14:36:00 +02:00

31 lines
602 B
Go

package dto
import "net/http"
type ApiError struct {
Code int `json:"code"`
Message string `json:"message"`
ValidationErrors []string `json:"validation_errors,omitempty"`
}
func NewApiError(code int) *ApiError {
return &ApiError{
Code: code,
Message: http.StatusText(code),
}
}
func (e *ApiError) WithValidationErrors(validationErrors []string) *ApiError {
e.ValidationErrors = validationErrors
return e
}
func (e *ApiError) WithMessage(message string) *ApiError {
e.Message = message
return e
}
func (e *ApiError) Error() string {
return e.Message
}