Skip to content

ref(hub): Remove _invokeClient #4972

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

Merged
merged 1 commit into from
Apr 28, 2022
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
48 changes: 30 additions & 18 deletions packages/hub/src/hub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,18 @@ export class Hub implements HubInterface {
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
public captureException(exception: any, hint?: EventHint): string {
const eventId = (this._lastEventId = hint && hint.event_id ? hint.event_id : uuid4());
this._invokeClient('captureException', exception, {
originalException: exception,
syntheticException: new Error('Sentry syntheticException'),
...hint,
event_id: eventId,
const syntheticException = new Error('Sentry syntheticException');
this._withClient((client, scope) => {
client.captureException(
exception,
{
originalException: exception,
syntheticException,
...hint,
event_id: eventId,
},
scope,
);
});
return eventId;
}
Expand All @@ -204,11 +211,19 @@ export class Hub implements HubInterface {
hint?: EventHint,
): string {
const eventId = (this._lastEventId = hint && hint.event_id ? hint.event_id : uuid4());
this._invokeClient('captureMessage', message, level, {
originalException: message,
syntheticException: new Error(message),
...hint,
event_id: eventId,
const syntheticException = new Error(message);
this._withClient((client, scope) => {
client.captureMessage(
message,
level,
{
originalException: message,
syntheticException,
...hint,
event_id: eventId,
},
scope,
);
});
return eventId;
}
Expand All @@ -222,9 +237,8 @@ export class Hub implements HubInterface {
this._lastEventId = eventId;
}

this._invokeClient('captureEvent', event, {
...hint,
event_id: eventId,
this._withClient((client, scope) => {
client.captureEvent(event, { ...hint, event_id: eventId }, scope);
});
return eventId;
}
Expand Down Expand Up @@ -446,12 +460,10 @@ export class Hub implements HubInterface {
* @param method The method to call on the client.
* @param args Arguments to pass to the client function.
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
private _invokeClient<M extends keyof Client>(method: M, ...args: any[]): void {
private _withClient(callback: (client: Client, scope: Scope | undefined) => void): void {
const { scope, client } = this.getStackTop();
if (client && client[method]) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any
(client as any)[method](...args, scope);
if (client) {
callback(client, scope);
}
}

Expand Down
7 changes: 0 additions & 7 deletions packages/hub/test/hub.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,6 @@ describe('Hub', () => {
expect(hub.getStack()).toHaveLength(1);
});

test("don't invoke client sync with wrong func", () => {
const hub = new Hub(clientFn);
// @ts-ignore we want to able to call private method
hub._invokeClient('funca', true);
expect(clientFn).not.toHaveBeenCalled();
});

test('isOlderThan', () => {
const hub = new Hub();
expect(hub.isOlderThan(0)).toBeFalsy();
Expand Down