Skip to content

Commit bbe9c2c

Browse files
committed
docs: add docs for the expressErrorCallback function
AdminForth/1781/image
1 parent 8dee375 commit bbe9c2c

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

adminforth/documentation/docs/tutorial/08-UsageOfLogger.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,27 @@ AF_LOG_SINGLE_LINE=true pnpm start
7070

7171
Accepted truthy values are `true` and `1`. When unset, logs use the default multi-line pretty format.
7272

73+
## Catching unhandled API handler errors
74+
75+
When an unhandled error is thrown inside an AdminForth API endpoint handler (built-in or custom), AdminForth logs the
76+
error and responds with `500 Internal server error`. If you also want to forward these errors somewhere — for example
77+
to report them to an external error-tracking service like [Sentry](https://sentry.io/), or to do your own custom
78+
logging — set the `expressErrorCallback` option in your AdminForth config:
79+
80+
```ts
81+
import AdminForth from 'adminforth';
82+
import * as Sentry from '@sentry/node';
83+
84+
export const admin = new AdminForth({
85+
// ...rest of your config
86+
expressErrorCallback: ({ error, extra, adminforth }) => {
87+
Sentry.captureException(error, {
88+
extra: {
89+
requestUrl: extra.requestUrl,
90+
query: extra.query,
91+
},
92+
});
93+
},
94+
});
95+
```
96+

0 commit comments

Comments
 (0)