@@ -1252,7 +1252,28 @@ export type AdminUserAuthorizeFunction = ((params?: {
12521252 allowed ?: boolean ,
12531253} > ) ;
12541254
1255-
1255+
1256+ /**
1257+ * Callback called when an unhandled error is thrown inside an AdminForth API endpoint handler.
1258+ * Useful to report errors to external services (e.g. Sentry) or to do custom logging.
1259+ * Thrown errors / rejections from this callback are caught and logged, they do not affect the response.
1260+ */
1261+ export type ExpressErrorCallbackFunction = ( ( params : {
1262+ /**
1263+ * The error thrown by the endpoint handler.
1264+ */
1265+ error : any ,
1266+ /**
1267+ * Adminforth instance.
1268+ */
1269+ adminforth : IAdminForth ,
1270+ /**
1271+ * Extra HTTP information about the request which caused the error.
1272+ */
1273+ extra : HttpExtra ,
1274+ } ) => void | Promise < void > ) ;
1275+
1276+
12561277/**
12571278 * Data source describes database connection which will be used to fetch data for resources.
12581279 * Each resource should use one data source.
@@ -1844,6 +1865,19 @@ export interface AdminForthInputConfig {
18441865 * List of plugins that should be applied in global scope.
18451866 */
18461867 globalPlugins ?: Array < IAdminForthPlugin > ,
1868+
1869+ /**
1870+ * Callback executed when an unhandled error is thrown inside an AdminForth API endpoint handler.
1871+ * Receives the thrown error and extra HTTP information about the request.
1872+ * Useful to report errors to external services (e.g. Sentry) or to do custom logging.
1873+ *
1874+ * ```ts
1875+ * expressErrorCallback: ({ error, extra }) => {
1876+ * Sentry.captureException(error, { extra: { url: extra.requestUrl } });
1877+ * },
1878+ * ```
1879+ */
1880+ expressErrorCallback ?: ExpressErrorCallbackFunction ,
18471881}
18481882
18491883
0 commit comments