Skip to content

Commit

Permalink
Functional fix for issue #2721
Browse files Browse the repository at this point in the history
  • Loading branch information
originalsouth committed Apr 2, 2024
1 parent 3b6bf48 commit 7b58bef
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
17 changes: 17 additions & 0 deletions octopoes/octopoes/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from octopoes.events.manager import get_rabbit_channel
from octopoes.models.exception import ObjectNotFoundException
from octopoes.version import __version__
from octopoes.xtdb.exceptions import NodeNotFound, ObjectNotFound

settings = Settings()
logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -78,6 +79,22 @@ def http_exception_handler(request: Request, exc: RequestError) -> JSONResponse:
)


@app.exception_handler(ObjectNotFound)
def object_not_found_exception_handler(request: Request, exc: ObjectNotFound) -> JSONResponse:
raise ObjectNotFoundException("Object not found")


@app.exception_handler(NodeNotFound)
def node_not_found_exception_handler(request: Request, exc: NodeNotFound) -> JSONResponse:
logger.info(exc)
return JSONResponse(
{
"value": "Node not found",
},
status.HTTP_404_NOT_FOUND,
)


@app.exception_handler(ObjectNotFoundException)
def not_found_exception_handler(request: Request, exc: ObjectNotFoundException) -> JSONResponse:
logger.info(exc)
Expand Down
9 changes: 7 additions & 2 deletions octopoes/octopoes/xtdb/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from pydantic import BaseModel, ConfigDict, Field, TypeAdapter

from octopoes.models.transaction import TransactionRecord
from octopoes.xtdb.exceptions import NodeNotFound, XTDBException
from octopoes.xtdb.exceptions import NodeNotFound, ObjectNotFound, XTDBException
from octopoes.xtdb.query import Query

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -63,7 +63,12 @@ def _verify_response(response: Response) -> None:
logger.error(response.request.url)
logger.error(response.request.content)
logger.error(response.text)
raise e
raise e
else:
if response.json() == {"error": "Node not found"}:
raise NodeNotFound
elif response.json()["error"].endswith("not found"):
raise ObjectNotFound

def client_url(self) -> str:
return f"/{self._client}"
Expand Down
4 changes: 4 additions & 0 deletions octopoes/octopoes/xtdb/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ class XTDBException(Exception):

class NodeNotFound(XTDBException):
"""The XTDB node was not found"""


class ObjectNotFound(XTDBException):
"""The XTDB object was not found"""

0 comments on commit 7b58bef

Please sign in to comment.