Skip to content

Commit

Permalink
allow pre_save_hook to cancel save with HTTPError
Browse files Browse the repository at this point in the history
currently, all errors in pre_save_hook are ignored,
making it impossible for pre_save_hook to be used for validation / quota enforcement / etc.

By allowing HTTPErrors to raise, save will be cancelled and the error message will be shown to the user
  • Loading branch information
minrk committed Mar 24, 2021
1 parent bf00ad0 commit 40f653d
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions jupyter_server/services/contents/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,13 @@ def run_pre_save_hook(self, model, path, **kwargs):
try:
self.log.debug("Running pre-save hook on %s", path)
self.pre_save_hook(model=model, path=path, contents_manager=self, **kwargs)
except HTTPError:
# allow custom HTTPErrors to raise,
# rejecting the save with a message.
raise
except Exception:
# unhandled errors don't prevent saving,
# which could cause frustrating data loss
self.log.error("Pre-save hook failed on %s", path, exc_info=True)

checkpoints_class = Type(Checkpoints, config=True)
Expand Down

0 comments on commit 40f653d

Please sign in to comment.