Description
Use case
The AppSync GraphQL resolver in Event Handler should allow customers to specify a
Solution/User Experience
The new feature should add a new method to the AppSyncGraphQLResolver
class called exceptionHandler
.
This method accepts an error class as first parameter (i.e. AssertionError
) and a function handler as second:
import { AppSyncGraphQLResolver } from '@aws-lambda-powertools/event-handler/appsync-graphql';
import type { Context } from 'aws-lambda';
const app = new AppSyncGraphQLResolver({ logger });
app.exceptionHandler(AssertionError, async (error) => {
return {
message: 'Error foo occurred'
}
});
app.onQuery('getTodo', async () => {
throw new AssertionError('foo')
export const handler = async (event: unknown, context: Context) =>
app.resolve(event, context);
Whenever an error in any of the other route handler is thrown, we should intercept it (around here) and check if there's any exception handler registered (we'll need a registry) that matches the error class being thrown.
If yes, we should call the exception handler and pass the error instance as first argument, and return its response as-is; if not, we should carry on the processing as it's implemented today.
The exceptionHandler()
method should also be available as TypeScript class method decorator, similar to how onQuery()
can.
Alternative solutions
Acknowledgment
- This feature request meets Powertools for AWS Lambda (TypeScript) Tenets
- Should this be considered in other Powertools for AWS Lambda languages? i.e. Python, Java, and .NET
Future readers
Please react with 👍 and your use case to help us understand customer demand.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status