Skip to content

Commit

Permalink
add error handling for error
Browse files Browse the repository at this point in the history
  • Loading branch information
DGaffney committed Jul 4, 2024
1 parent e6997ab commit 70f0c76
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lib/model/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from lib.helpers import get_class
from lib import schemas
from lib.cache import Cache
from lib.sentry import capture_custom_message

class Model(ABC):
BATCH_SIZE = 1
Expand Down Expand Up @@ -40,7 +41,15 @@ def get_tempfile(self) -> Any:

def process(self, messages: Union[List[schemas.Message], schemas.Message]) -> List[schemas.Message]:
return []


def handle_fingerprinting_error(self, e):
error_context = {"error": str(e)}
for attr in ["__cause__", "__context__", "args", "__traceback__"]:
if attr in dir(e):
error_context[attr] = getattr(e, attr)
capture_custom_message("Error during fingerprinting for {self.model_name}", 'info', error_context)
return schemas.ErrorResponse(error=str(e), error_details={"exception": str(e)})

def get_response(self, message: schemas.Message) -> schemas.GenericItem:
"""
Perform a lookup on the cache for a message, and if found, return that cached value.
Expand All @@ -51,7 +60,7 @@ def get_response(self, message: schemas.Message) -> schemas.GenericItem:
result = self.process(message)
Cache.set_cached_result(message.body.content_hash, result)
except Exception as e:
return schemas.ErrorResponse(error=str(e), error_details={"exception": str(e)})
return self.handle_fingerprinting_error(e)
return result

def respond(self, messages: Union[List[schemas.Message], schemas.Message]) -> List[schemas.Message]:
Expand Down

0 comments on commit 70f0c76

Please sign in to comment.