Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion optimade/filtertransformers/elasticsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from elasticsearch_dsl import Q, Text, Keyword, Integer, Field
from optimade.models import CHEMICAL_SYMBOLS, ATOMIC_NUMBERS
from optimade.filtertransformers import BaseTransformer
from optimade.server.exceptions import BadRequest

__all__ = ("ElasticTransformer",)

Expand Down Expand Up @@ -352,7 +353,7 @@ def property(self, args):
quantity_name = args[0]

if quantity_name not in self.index_mapping:
raise Exception("%s is not a searchable quantity" % quantity_name)
raise BadRequest(detail=f"{quantity_name} is not a searchable quantity")

quantity = self.index_mapping.get(quantity_name, None)
if quantity is None:
Expand Down
5 changes: 5 additions & 0 deletions optimade/server/exception_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from optimade.server.config import CONFIG
from optimade.server.logger import LOGGER
from optimade.server.routers.utils import meta_values
from optimade.server.exceptions import BadRequest


def general_exception(
Expand Down Expand Up @@ -91,6 +92,10 @@ def validation_exception_handler(request: Request, exc: ValidationError):


def grammar_not_implemented_handler(request: Request, exc: VisitError):
orig_exc = getattr(exc, "orig_exc", None)
if isinstance(orig_exc, BadRequest):
return general_exception(request, orig_exc)

rule = getattr(exc.obj, "data", getattr(exc.obj, "type", str(exc)))

status = 501
Expand Down
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pytest==6.2.1
pytest-cov==2.10.1
pytest-cov==2.11.1
codecov==2.1.11
jsondiff==1.2.0
pylint==2.6.0
Expand Down