feat(filter): add better error message when passing an invalid filter expression
This commit is contained in:
parent
9d3fb6f81d
commit
c6b682507a
@ -96,6 +96,7 @@ This document describes the different errors Vikunja can return.
|
||||
| 4021 | 400 | This user is already assigned to that task. |
|
||||
| 4022 | 400 | The task has a relative reminder which does not specify relative to what. |
|
||||
| 4023 | 409 | Tried to create a task relation which would create a cycle. |
|
||||
| 4024 | 400 | The provided filter expression is invalid. |
|
||||
|
||||
## Team
|
||||
|
||||
|
@ -1021,7 +1021,7 @@ func (err ErrTaskRelationCycle) Error() string {
|
||||
}
|
||||
|
||||
// ErrCodeTaskRelationCycle holds the unique world-error code of this error
|
||||
const ErrCodeTaskRelationCycle = 4022
|
||||
const ErrCodeTaskRelationCycle = 4023
|
||||
|
||||
// HTTPError holds the http error description
|
||||
func (err ErrTaskRelationCycle) HTTPError() web.HTTPError {
|
||||
@ -1032,6 +1032,34 @@ func (err ErrTaskRelationCycle) HTTPError() web.HTTPError {
|
||||
}
|
||||
}
|
||||
|
||||
// ErrInvalidFilterExpression represents an error where the task filter expression was invalid
|
||||
type ErrInvalidFilterExpression struct {
|
||||
Expression string
|
||||
ExpressionError error
|
||||
}
|
||||
|
||||
// IsErrInvalidFilterExpression checks if an error is ErrInvalidFilterExpression.
|
||||
func IsErrInvalidFilterExpression(err error) bool {
|
||||
_, ok := err.(ErrInvalidFilterExpression)
|
||||
return ok
|
||||
}
|
||||
|
||||
func (err ErrInvalidFilterExpression) Error() string {
|
||||
return fmt.Sprintf("Task filter expression is invalid [ExpressionError: %v]", err.ExpressionError)
|
||||
}
|
||||
|
||||
// ErrCodeInvalidFilterExpression holds the unique world-error code of this error
|
||||
const ErrCodeInvalidFilterExpression = 4024
|
||||
|
||||
// HTTPError holds the http error description
|
||||
func (err ErrInvalidFilterExpression) HTTPError() web.HTTPError {
|
||||
return web.HTTPError{
|
||||
HTTPCode: http.StatusBadRequest,
|
||||
Code: ErrCodeInvalidFilterExpression,
|
||||
Message: fmt.Sprintf("The filter expression '%s' is invalid: %v", err.Expression, err.ExpressionError),
|
||||
}
|
||||
}
|
||||
|
||||
// ============
|
||||
// Team errors
|
||||
// ============
|
||||
|
@ -152,7 +152,10 @@ func getTaskFiltersByCollections(c *TaskCollection) (filters []*taskFilter, err
|
||||
|
||||
parsedFilter, err := fexpr.Parse(c.Filter)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, &ErrInvalidFilterExpression{
|
||||
Expression: c.Filter,
|
||||
ExpressionError: err,
|
||||
}
|
||||
}
|
||||
|
||||
filters = make([]*taskFilter, 0, len(parsedFilter))
|
||||
|
Loading…
x
Reference in New Issue
Block a user