Skip to content

Commit dc59c9e

Browse files
committed
Added onError callback
1 parent f69d056 commit dc59c9e

File tree

2 files changed

+117
-62
lines changed

2 files changed

+117
-62
lines changed

README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,44 @@ The `accessTokenTTL` override is particularly useful when the application is als
262262

263263
The `props` values are end-to-end encrypted, so they can safely contain sensitive information.
264264

265+
## Custom Error Responses
266+
267+
By using the `onError` option, you can emit notifications or take other actions when an error response was to be emitted:
268+
269+
```ts
270+
new OAuthProvider({
271+
// ... other options ...
272+
onError({ code, description, status, headers }) {
273+
console.error(`Error ${code}: ${description}`)
274+
}
275+
})
276+
```
277+
278+
Or sending events to an external system as required:
279+
280+
```ts
281+
new OAuthProvider({
282+
// ... other options ...
283+
onError({ code, description, status, headers }) {
284+
Sentry.captureMessage(/* ... */)
285+
}
286+
})
287+
```
288+
289+
By returning a `Response` you can also override what the OAuthProvider returns to your users:
290+
291+
```ts
292+
new OAuthProvider({
293+
// ... other options ...
294+
onError({ code, description, status, headers }) {
295+
if (code === 'unsupported_grant_type') {
296+
return new Response('...', { status, headers })
297+
}
298+
// returning undefined (i.e. void) uses the default Response generation
299+
}
300+
})
301+
```
302+
265303
## Implementation Notes
266304

267305
### End-to-end encryption

0 commit comments

Comments
 (0)