Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow OnErrorCallbacks to return Promise<boolean> #1224

Merged
merged 5 commits into from
Jan 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## TBD

### Fixed

- (core): the `OnErrorCallback` type definition now allows `Promise<boolean>` as a return type. [#1224](https://github.com/bugsnag/bugsnag-js/pull/1224)

## v7.5.6 (2021-01-11)

### Changed
Expand All @@ -22,7 +28,6 @@
- Add configuration option to control maximum number of persisted events/sessions [bugsnag-android#980](https://github.com/bugsnag/bugsnag-android/pull/980)
- Increase kotlin dependency version to 1.3.72 [bugsnag-android#1050](https://github.com/bugsnag/bugsnag-android/pull/1050)


## v7.5.5 (2020-12-14)

### Changed
Expand Down
20 changes: 20 additions & 0 deletions packages/core/test/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,26 @@ describe('@bugsnag/core/client', () => {
process.nextTick(() => done())
})

// eslint-disable-next-line jest/expect-expect
it('supports preventing send by returning a Promise that resolves to false in onError callback', done => {
const client = new Client({
apiKey: 'API_KEY_YEAH',
onError: () => Promise.resolve(false)
})

client._setDelivery(client => ({
sendEvent: (payload) => {
done('sendEvent() should not be called')
},
sendSession: () => {}
}))

client.notify(new Error('oh em gee'), () => {}, () => {
// give the event loop a tick to see if the event gets sent
process.nextTick(() => done())
})
})

// eslint-disable-next-line jest/expect-expect
it('supports preventing send by returning false in notify callback', done => {
const client = new Client({ apiKey: 'API_KEY_YEAH' })
Expand Down
2 changes: 1 addition & 1 deletion packages/core/types/common.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export interface Config {
user?: User | null
}

export type OnErrorCallback = (event: Event, cb?: (err: null | Error) => void) => void | Promise<void> | boolean;
export type OnErrorCallback = (event: Event, cb: (err: null | Error, shouldSend?: boolean) => void) => void | boolean | Promise<void | boolean>
export type OnSessionCallback = (session: Session) => void | boolean;
export type OnBreadcrumbCallback = (breadcrumb: Breadcrumb) => void | boolean;

Expand Down