Skip to content

Commit e9d8904

Browse files
committed
rename to handleErrorWithSentry
1 parent d21dd18 commit e9d8904

File tree

7 files changed

+31
-7
lines changed

7 files changed

+31
-7
lines changed

packages/sveltekit/src/client/handleError.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import type { HandleClientError, NavigationEvent } from '@sveltejs/kit';
1111
*
1212
* @param handleError The original SvelteKit error handler.
1313
*/
14-
export function wrapHandleErrorWithSentry(handleError: HandleClientError): HandleClientError {
14+
export function handleErrorWithSentry(handleError?: HandleClientError): HandleClientError {
1515
return (input: { error: unknown; event: NavigationEvent }): ReturnType<HandleClientError> => {
1616
captureException(input.error, scope => {
1717
scope.addEventProcessor(event => {
@@ -23,6 +23,8 @@ export function wrapHandleErrorWithSentry(handleError: HandleClientError): Handl
2323
});
2424
return scope;
2525
});
26-
return handleError(input);
26+
if (handleError) {
27+
return handleError(input);
28+
}
2729
};
2830
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export * from '@sentry/svelte';
22

33
export { init } from './sdk';
4-
export { wrapHandleErrorWithSentry } from './handleError';
4+
export { handleErrorWithSentry } from './handleError';
55

66
// Just here so that eslint is happy until we export more stuff here
77
export const PLACEHOLDER_CLIENT = 'PLACEHOLDER';

packages/sveltekit/src/index.types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import type * as serverSdk from './server';
1717
/** Initializes Sentry SvelteKit SDK */
1818
export declare function init(options: Options | clientSdk.BrowserOptions | serverSdk.NodeOptions): void;
1919

20-
export declare function wrapHandleErrorWithSentry<T extends HandleClientError | HandleServerError>(
20+
export declare function handleErrorWithSentry<T extends HandleClientError | HandleServerError>(
2121
handleError: T,
2222
): ReturnType<T>;
2323

packages/sveltekit/src/server/handleError.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import type { HandleServerError, RequestEvent } from '@sveltejs/kit';
1111
*
1212
* @param handleError The original SvelteKit error handler.
1313
*/
14-
export function wrapHandleErrorWithSentry(handleError: HandleServerError): HandleServerError {
14+
export function handleErrorWithSentry(handleError?: HandleServerError): HandleServerError {
1515
return (input: { error: unknown; event: RequestEvent }): ReturnType<HandleServerError> => {
1616
captureException(input.error, scope => {
1717
scope.addEventProcessor(event => {
@@ -23,6 +23,8 @@ export function wrapHandleErrorWithSentry(handleError: HandleServerError): Handl
2323
});
2424
return scope;
2525
});
26-
return handleError(input);
26+
if (handleError) {
27+
return handleError(input);
28+
}
2729
};
2830
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export * from '@sentry/node';
22

33
export { init } from './sdk';
4-
export { wrapHandleErrorWithSentry } from './handleError';
4+
export { handleErrorWithSentry } from './handleError';

packages/sveltekit/test/client/handleError.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@ describe('handleError', () => {
5555
mockScope = new Scope();
5656
});
5757

58+
it('works when a handleError func is not provided', async () => {
59+
const wrappedHandleError = wrapHandleErrorWithSentry();
60+
const mockError = new Error('test');
61+
const returnVal = await wrappedHandleError({ error: mockError, event: navigationEvent });
62+
63+
expect(returnVal).not.toBeDefined();
64+
expect(mockCaptureException).toHaveBeenCalledTimes(1);
65+
expect(mockCaptureException).toHaveBeenCalledWith(mockError, expect.any(Function));
66+
});
67+
5868
it('calls captureException', async () => {
5969
const wrappedHandleError = wrapHandleErrorWithSentry(handleError);
6070
const mockError = new Error('test');

packages/sveltekit/test/server/handleError.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@ describe('handleError', () => {
4747
mockScope = new Scope();
4848
});
4949

50+
it('works when a handleError func is not provided', async () => {
51+
const wrappedHandleError = wrapHandleErrorWithSentry();
52+
const mockError = new Error('test');
53+
const returnVal = await wrappedHandleError({ error: mockError, event: requestEvent });
54+
55+
expect(returnVal).not.toBeDefined();
56+
expect(mockCaptureException).toHaveBeenCalledTimes(1);
57+
expect(mockCaptureException).toHaveBeenCalledWith(mockError, expect.any(Function));
58+
});
59+
5060
it('calls captureException', async () => {
5161
const wrappedHandleError = wrapHandleErrorWithSentry(handleError);
5262
const mockError = new Error('test');

0 commit comments

Comments
 (0)