Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(event_handler): add exception handling mechanism for AppSyncResolver #5588

Merged
merged 4 commits into from
Nov 19, 2024

Conversation

leandrodamascena
Copy link
Contributor

Issue number: #2184

Summary

Changes

This PR introduces a new feature to handle exceptions in AppSyncResolver using a standard error handling mechanism, similar to the one used for HTTP Resolvers. Currently, there is no built-in support for exception handling in AppSyncResolver, and this PR aims to address that gap.

Changes

  1. Added exception catching function: A new decorator @app.exception_handler has been implemented to catch and handle exceptions raised during the execution of AppSync resolvers. This decorator allows developers to define custom error handling logic based on the type of exception raised.

  2. Added tests: Test cases have been added to ensure the proper functioning of the exception handling mechanism and to maintain code quality.

  3. Added documentation: The usage and implementation details of the @app.exception_handler decorator have been documented to provide guidance for developers who wish to utilize this new feature.

Note

It's important to note that this exception handling mechanism is not supported when using single async resolvers.

User experience

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(id: str):
    raise ValueError("Error")

def lambda_handler(event, context):
    return app.resolve(event, context)

Checklist

If your change doesn't seem to apply, please leave them unchecked.

Is this a breaking change?

RFC issue number:

Checklist:

  • Migration process documented
  • Implement warnings (if it can live side by side)

Acknowledgment

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

@pull-request-size pull-request-size bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Nov 19, 2024
@github-actions github-actions bot added the feature New feature or functionality label Nov 19, 2024
@boring-cyborg boring-cyborg bot added the documentation Improvements or additions to documentation label Nov 19, 2024
@leandrodamascena leandrodamascena marked this pull request as ready for review November 19, 2024 14:08
@leandrodamascena leandrodamascena requested a review from a team as a code owner November 19, 2024 14:08
@leandrodamascena leandrodamascena changed the title feat(event_handler): add exception handling mechanism for AppSyncResolver - WIP feat(event_handler): add exception handling mechanism for AppSyncResolver Nov 19, 2024
@github-actions github-actions bot removed the documentation Improvements or additions to documentation label Nov 19, 2024
@boring-cyborg boring-cyborg bot added the documentation Improvements or additions to documentation label Nov 19, 2024
@leandrodamascena leandrodamascena linked an issue Nov 19, 2024 that may be closed by this pull request
2 tasks
@github-actions github-actions bot removed the documentation Improvements or additions to documentation label Nov 19, 2024
Copy link

codecov bot commented Nov 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.16%. Comparing base (150623b) to head (d4950b2).
Report is 3 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #5588   +/-   ##
========================================
  Coverage    96.16%   96.16%           
========================================
  Files          229      229           
  Lines        10836    10853   +17     
  Branches      2015     2018    +3     
========================================
+ Hits         10420    10437   +17     
  Misses         327      327           
  Partials        89       89           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

@leandrodamascena leandrodamascena self-assigned this Nov 19, 2024
@leandrodamascena leandrodamascena merged commit db8a338 into develop Nov 19, 2024
15 checks passed
@leandrodamascena leandrodamascena deleted the appsync-handler-exception branch November 19, 2024 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
event_handlers feature New feature or functionality size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature Request: exception handling mechanism for AppSyncResolver
2 participants