diff --git a/src/image2structure/filter/file_filters/toxicity_filter.py b/src/image2structure/filter/file_filters/toxicity_filter.py index 07af913..c829201 100644 --- a/src/image2structure/filter/file_filters/toxicity_filter.py +++ b/src/image2structure/filter/file_filters/toxicity_filter.py @@ -128,7 +128,13 @@ def callback(request_id: str, response: Dict, error: HttpError): ) with self._client_lock: - batch_request.execute() + try: + batch_request.execute() + # Handle socket.timeout, httplib2.HttpLib2Error, and googleapiclient.errors.HttpError + except (HttpLib2Error, HttpError) as e: + raise FileFilterError( + f"Error was thrown when making a request to Perspective API: {e}" + ) from e batch_response = text_to_response except (BatchError, HttpLib2Error, HttpError) as e: