Skip to content

Commit 3f162e4

Browse files
committed
Handle errors building queries URL query
The exception being caught (QueryValueError) was never being raised and the TypeErrors being raised instead caused 503 server errors when fields were missing or invalid. Catching TypeError instead allows the client to get a `400 Bad Request` error with the exception detail as intended.
1 parent 6088e73 commit 3f162e4

File tree

2 files changed

+2
-6
lines changed

2 files changed

+2
-6
lines changed

tiled/queries.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,3 @@ def __ge__(self, value):
632632
# Note: __contains__ cannot be supported because the language coerces
633633
# the result of __contains__ to be a literal boolean. We are not
634634
# allowed to return a custom type.
635-
636-
637-
class QueryValueError(ValueError):
638-
pass

tiled/server/core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from .. import queries
2525
from ..adapters.mapping import MapAdapter
2626
from ..links import links_for_node
27-
from ..queries import KeyLookup, QueryValueError
27+
from ..queries import KeyLookup
2828
from ..serialization import register_builtin_serializers
2929
from ..structures.core import Spec, StructureFamily
3030
from ..utils import (
@@ -184,7 +184,7 @@ async def apply_search(tree, filters, query_registry):
184184
key_lookups.append(query.key)
185185
continue
186186
tree = tree.search(query)
187-
except QueryValueError as err:
187+
except TypeError as err:
188188
raise HTTPException(
189189
status_code=HTTP_400_BAD_REQUEST, detail=err.args[0]
190190
)

0 commit comments

Comments
 (0)