Skip to content

Commit 10adbb9

Browse files
committed
fix: enhance exception handling documentation and add example resolver
1 parent 9366f86 commit 10adbb9

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

docs/features/event-handler/appsync-graphql.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,16 +150,24 @@ You can access the original Lambda event or context for additional information.
150150

151151
### Exception Handling
152152

153-
You can use the **`exceptionHandler`** method with any exception. This allows you to handle common errors outside your resolver and return a custom response.
153+
You can use the **`exceptionHandler`** method to handle any exception. This allows you to handle common errors outside your resolver and return a custom response.
154154

155-
You can use a VTL response mapping template to detect these custom responses and forward them to the client gracefully.
155+
The **`exceptionHandler`** method also supports passing an array of exceptions that you wish to handle with a single handler.
156+
157+
You can use an AppSync JavaScript resolver or a VTL response mapping template to detect these custom responses and forward them to the client gracefully.
156158

157159
=== "Exception Handling"
158160

159161
```typescript hl_lines="11-18 21-23"
160162
--8<-- "examples/snippets/event-handler/appsync-graphql/exceptionHandling.ts"
161163
```
162164

165+
=== "APPSYNC JS Resolver"
166+
167+
```js hl_lines="11-13"
168+
--8<-- "examples/snippets/event-handler/appsync-graphql/exceptionHandlingResolver.js"
169+
```
170+
163171
=== "VTL Response Mapping Template"
164172

165173
```velocity hl_lines="1-3"
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { util } from '@aws-appsync/utils';
2+
3+
export function request(ctx) {
4+
return {
5+
operation: 'Invoke',
6+
payload: ctx,
7+
};
8+
}
9+
10+
export function response(ctx) {
11+
if (ctx.result.error) {
12+
return util.error(ctx.result.error.message, ctx.result.error.type);
13+
}
14+
return ctx.result;
15+
}

0 commit comments

Comments
 (0)