Skip to content

Commit 7aa6088

Browse files
author
cgohlke
committed
improve doc for errormapping (see issue spring-media#24, thanks to @mohitp-cci)
1 parent 0c75b92 commit 7aa6088

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,21 @@ exports.handler = router.handler({
103103
{
104104
path: '/graphql',
105105
method: 'POST',
106-
action: (request, context) => doAnything(request.body)
106+
action: (request, context) => doThrowAnException(request.body)
107107
}
108108
],
109109
debug: true,
110110
errorMapping: {
111111
'NotFound': 404,
112+
'MyCustomError': 429,
112113
'ServerError': 500
113114
}
114115
}
115116
});
117+
118+
function doThrowAnException(body) {
119+
throw {reason: 'MyCustomError', message: 'Throw an error for this example'}
120+
}
116121
```
117122
118123
With the key word `errorMapping` shown in the example above you can custom mapping of thrown errors to http response code error.

0 commit comments

Comments
 (0)