-
Notifications
You must be signed in to change notification settings - Fork 401
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(event_handler): add exception handling mechanism for AppSyncReso…
…lver (#5588) * Adding exception handler support * Adding exception handler support - fix tests * Adding exception handler support - fix tests + docs
- Loading branch information
1 parent
3ff5132
commit db8a338
Showing
6 changed files
with
232 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
examples/event_handler_graphql/src/exception_handling_graphql.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from aws_lambda_powertools.event_handler import AppSyncResolver | ||
|
||
app = AppSyncResolver() | ||
|
||
|
||
@app.exception_handler(ValueError) | ||
def handle_value_error(ex: ValueError): | ||
return {"message": "error"} | ||
|
||
|
||
@app.resolver(field_name="createSomething") | ||
def create_something(): | ||
raise ValueError("Raising an exception") | ||
|
||
|
||
def lambda_handler(event, context): | ||
return app.resolve(event, context) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters