Files
payload/packages/plugin-sentry/src/plugin.ts
Elliot DeNolf 142616e6ad chore(eslint): curly [skip-lint] (#7959)
Now enforcing curly brackets on all if statements. Includes auto-fixer.


```ts
//  Bad
if (foo) foo++;

//  Good
if (foo) {
  foo++;
}
```




Note: this did not lint the `drizzle` package or any `db-*` packages.
This will be done in the future.
2024-08-29 10:15:36 -04:00

34 lines
840 B
TypeScript

import type { Config } from 'payload'
import type { PluginOptions } from './types.js'
import { captureException } from './captureException.js'
import { startSentry } from './startSentry.js'
export const sentryPlugin =
(pluginOptions: PluginOptions) =>
(incomingConfig: Config): Config => {
const config = { ...incomingConfig }
if (pluginOptions.enabled === false || !pluginOptions.dsn) {
return config
}
config.hooks = {
...(incomingConfig.hooks || {}),
// eslint-disable-next-line @typescript-eslint/no-explicit-any
afterError: (err: any) => {
captureException(err)
},
}
config.onInit = async (payload) => {
if (incomingConfig.onInit) {
await incomingConfig.onInit(payload)
}
startSentry(pluginOptions, payload)
}
return config
}