-
Notifications
You must be signed in to change notification settings - Fork 504
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(NabuError): log all nabu errors to segment
- Loading branch information
1 parent
54ce539
commit babeda1
Showing
10 changed files
with
105 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
...ror/utils/createNabuErrorAnalyticsInterceptor/createNabuErrorAnalyticsInterceptor.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { createNabuErrorAnalyticsInterceptor, NabuError } from 'services/errors' | ||
|
||
describe('createNabuErrorAnalyticsInterceptor()', () => { | ||
it('Should not handle error that is not nabu', async () => { | ||
const dispatchSpy = jest.fn() | ||
const error = new Error() | ||
|
||
const interceptor = createNabuErrorAnalyticsInterceptor(dispatchSpy) | ||
|
||
const promise = interceptor(error) | ||
|
||
await expect(promise).rejects.toEqual(error) | ||
|
||
expect(dispatchSpy).not.toHaveBeenCalled() | ||
}) | ||
|
||
it('Should push the nabu error to the analytics service', async () => { | ||
const dispatchSpy = jest.fn() | ||
const error = new NabuError({ | ||
categories: ['TestCategory'], | ||
message: 'Message', | ||
title: 'Error title' | ||
}) | ||
|
||
const interceptor = createNabuErrorAnalyticsInterceptor(dispatchSpy) | ||
|
||
const promise = interceptor(error) | ||
|
||
await expect(promise).rejects.toEqual(error) | ||
|
||
expect(dispatchSpy).toHaveBeenCalledWith({ | ||
payload: { | ||
key: 'Client Error', | ||
properties: { | ||
category: ['TestCategory'], | ||
error: 'NABU_ERROR', | ||
network_error_description: error.message, | ||
network_error_type: 'NABU_ERROR', | ||
source: 'NABU', | ||
title: error.title | ||
} | ||
}, | ||
type: 'trackEvent' | ||
}) | ||
}) | ||
}) |
29 changes: 29 additions & 0 deletions
29
...abuError/utils/createNabuErrorAnalyticsInterceptor/createNabuErrorAnalyticsInterceptor.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { actions } from 'data' | ||
import { ClientErrorProperties } from 'data/analytics/types/errors' | ||
import { Analytics } from 'data/types' | ||
|
||
import { isNabuError } from '../isNabuError' | ||
import { CreateNabuErrorAnalyticsInterceptorUtility } from './createNabuErrorAnalyticsInterceptor.types' | ||
|
||
export const createNabuErrorAnalyticsInterceptor: CreateNabuErrorAnalyticsInterceptorUtility = | ||
(dispatch) => (error) => { | ||
if (isNabuError(error)) { | ||
const clientError: ClientErrorProperties = { | ||
category: error.categories, | ||
error: 'NABU_ERROR', | ||
network_error_description: error.message, | ||
network_error_type: 'NABU_ERROR', | ||
source: 'NABU', | ||
title: error.title | ||
} | ||
|
||
dispatch( | ||
actions.analytics.trackEvent({ | ||
key: Analytics.CLIENT_ERROR, | ||
properties: clientError | ||
}) | ||
) | ||
} | ||
|
||
return Promise.reject(error) | ||
} |
5 changes: 5 additions & 0 deletions
5
...or/utils/createNabuErrorAnalyticsInterceptor/createNabuErrorAnalyticsInterceptor.types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { Dispatch } from 'redux' | ||
|
||
export type CreateNabuErrorAnalyticsInterceptorUtility = ( | ||
dispatch: Dispatch | ||
) => (error: Error) => Promise<Error> |
1 change: 1 addition & 0 deletions
1
...frontend/src/services/errors/NabuError/utils/createNabuErrorAnalyticsInterceptor/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './createNabuErrorAnalyticsInterceptor' |
1 change: 1 addition & 0 deletions
1
packages/blockchain-wallet-v4-frontend/src/services/errors/NabuError/utils/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters