Skip to content

Commit

Permalink
Add decorator for eception handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
Garulf committed Jan 25, 2024
1 parent 11622e5 commit 8df9316
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pyflowlauncher/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ def add_exception_handler(self, exception: Type[Exception], handler: Callable[..
"""Add exception handler to be called when an exception is raised in a method."""
self._event_handler.add_exception_handler(exception, handler)

def on_except(self, exception: Type[Exception]) -> Callable[..., Any]:
@wraps(exception)
def wrapper(handler: Callable[..., Any]) -> Callable[..., Any]:
self.add_exception_handler(exception, handler)
return handler
return wrapper

def action(self, method: Method, parameters: Optional[Iterable] = None) -> JsonRPCAction:
"""Register a method and return a JsonRPCAction that calls it."""
method_name = self.add_method(method)
Expand Down

0 comments on commit 8df9316

Please sign in to comment.