Skip to content

Commit

Permalink
Tweak error handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
rebeccacremona committed Aug 1, 2024
1 parent 4057c27 commit 7493746
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 19 deletions.
13 changes: 0 additions & 13 deletions web/main/templates/export_too_large.html

This file was deleted.

4 changes: 2 additions & 2 deletions web/main/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ def get_link_title(url: str) -> str:
return title[0].text


class LambdaExportTooLarge(RuntimeError):
class LambdaException(RuntimeError):
pass


Expand Down Expand Up @@ -765,7 +765,7 @@ def export_via_aws_lambda(obj, html, file_type):
except (BotoCoreError, BotoClientError, requests.RequestException, AssertionError) as e:
if export_type == "Casebook":
obj.inc_export_fails()
raise Exception(f"AWS Lambda export failed: {str(e)}")
raise LambdaException(f"AWS Lambda export failed: {str(e)}")

finally:
# remove the source html from s3
Expand Down
9 changes: 5 additions & 4 deletions web/main/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
)
from .utils import (
BadFiletypeError,
LambdaExportTooLarge,
LambdaException,
StringFileResponse,
fix_after_rails,
get_link_title,
Expand Down Expand Up @@ -2771,11 +2771,12 @@ def export(request: HttpRequest, node: Union[ContentNode, Casebook], file_type="
file_type,
export_options=export_options,
)
except LambdaExportTooLarge as too_large:
logger.warning(f"Export node({node.id}): " + too_large.args[0])
return render(request, "export_too_large.html", {"casebook": node})
except LambdaException as e:
logger.exception(f"Export of node {node.id} failed.")
return render(request, "export_error.html", {"casebook": node})
if response_data is None:
return render(request, "export_error.html", {"casebook": node})

# return html
if file_type == "html":
return HttpResponse(response_data)
Expand Down

0 comments on commit 7493746

Please sign in to comment.