Skip to content

Feature request: support error handling in AppSync GraphQL #4130

Open
@dreamorosi

Description

@dreamorosi

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

Future readers

Please react with 👍 and your use case to help us understand customer demand.

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmedThe scope is clear, ready for implementationevent-handlerThis item relates to the Event Handler Utilityfeature-requestThis item refers to a feature request for an existing or new utilityhelp-wantedWe would really appreciate some support from community for this one

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions