Skip to content

Commit c73505a

Browse files
committed
fix(core): Fix error handling when sending envelopes
1 parent 08c30f8 commit c73505a

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

packages/core/src/client.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -415,10 +415,9 @@ export abstract class Client<O extends ClientOptions = ClientOptions> {
415415
env = addItemToEnvelope(env, createAttachmentEnvelopeItem(attachment));
416416
}
417417

418-
const promise = this.sendEnvelope(env);
419-
if (promise) {
420-
promise.then(sendResponse => this.emit('afterSendEvent', event, sendResponse), null);
421-
}
418+
// sendEnvelope should not throw
419+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
420+
this.sendEnvelope(env).then(sendResponse => this.emit('afterSendEvent', event, sendResponse));
422421
}
423422

424423
/**
@@ -876,16 +875,18 @@ export abstract class Client<O extends ClientOptions = ClientOptions> {
876875
public sendEnvelope(envelope: Envelope): PromiseLike<TransportMakeRequestResponse> {
877876
this.emit('beforeEnvelope', envelope);
878877

879-
if (this._isEnabled() && this._transport) {
880-
return this._transport.send(envelope).then(null, reason => {
881-
DEBUG_BUILD && debug.error('Error while sending envelope:', reason);
882-
return reason;
883-
});
878+
if (!this._isEnabled() || !this._transport) {
879+
DEBUG_BUILD && debug.error('Transport disabled');
880+
return resolvedSyncPromise({});
884881
}
885882

886-
DEBUG_BUILD && debug.error('Transport disabled');
887-
888-
return resolvedSyncPromise({});
883+
return this._transport.send(envelope).then(
884+
response => response,
885+
reason => {
886+
DEBUG_BUILD && debug.error('Error while sending envelope:', reason);
887+
return {};
888+
},
889+
);
889890
}
890891

891892
/* eslint-enable @typescript-eslint/unified-signatures */

packages/core/test/lib/client.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2268,7 +2268,7 @@ describe('Client', () => {
22682268

22692269
expect(mockSend).toBeCalledTimes(1);
22702270
expect(callback).toBeCalledTimes(1);
2271-
expect(callback).toBeCalledWith(errorEvent, 'send error');
2271+
expect(callback).toBeCalledWith(errorEvent, {});
22722272
});
22732273

22742274
it('passes the response to the hook', async () => {

0 commit comments

Comments
 (0)