Skip to content

Commit d3ec755

Browse files
HazATkamilogorek
authored andcommitted
feat: Add values to exception interface
1 parent b85398f commit d3ec755

File tree

7 files changed

+25
-59
lines changed

7 files changed

+25
-59
lines changed

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"**/dist/": true
1414
},
1515
"typescript.tsdk": "./node_modules/typescript/lib",
16-
"tslint.enable": false,
16+
"tslint.autoFixOnSave": true,
1717
"[json]": {
1818
"editor.formatOnType": false,
1919
"editor.formatOnPaste": false,

packages/browser/src/backend.ts

Lines changed: 5 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,11 @@
11
import { Backend, Options, SentryError } from '@sentry/core';
22
import { addBreadcrumb, captureEvent } from '@sentry/minimal';
3-
import { SentryEvent, SentryException } from '@sentry/types';
3+
import { SentryEvent } from '@sentry/types';
44
import { Raven, SendMethod } from './raven';
55

66
/** Original raven send function. */
77
const sendRavenEvent = Raven._sendProcessedPayload.bind(Raven) as SendMethod;
88

9-
/** Normalizes the event so it is consistent with our domain interface. */
10-
function normalizeRavenEvent(event?: SentryEvent): SentryEvent | undefined {
11-
const ex = ((event && event.exception) || {}) as {
12-
values?: SentryException[];
13-
};
14-
if (event && ex && ex.values) {
15-
event.exception = ex.values;
16-
}
17-
return event;
18-
}
19-
20-
/** Prepares an event so it can be send with raven-js. */
21-
function prepareEventForRaven(event: SentryEvent): SentryEvent {
22-
const ravenEvent = event as any;
23-
if (event.exception) {
24-
// tslint:disable-next-line:no-unsafe-any
25-
ravenEvent.exception = { values: event.exception };
26-
}
27-
return ravenEvent as SentryEvent;
28-
}
29-
309
/**
3110
* Configuration options for the Sentry Browser SDK.
3211
* @see BrowserClient for more information.
@@ -95,15 +74,7 @@ export class BrowserBackend implements Backend {
9574
return false;
9675
});
9776

98-
// Hook into Raven's internal event sending mechanism. This allows us to
99-
// pass events to the client, before they will be sent back here for
100-
// actual submission.
101-
Raven._sendProcessedPayload = event => {
102-
const normalizedEvent = normalizeRavenEvent(event);
103-
if (normalizedEvent) {
104-
captureEvent(normalizedEvent);
105-
}
106-
};
77+
Raven._sendProcessedPayload = captureEvent;
10778

10879
return true;
10980
}
@@ -119,11 +90,7 @@ export class BrowserBackend implements Backend {
11990
event = evt;
12091
};
12192
Raven.captureException(exception);
122-
const normalizedEvent = normalizeRavenEvent(event);
123-
if (normalizedEvent) {
124-
return normalizedEvent;
125-
}
126-
throw new SentryError('Event was undefined when it should be an event');
93+
return event;
12794
} finally {
12895
Raven._sendProcessedPayload = originalSend;
12996
}
@@ -140,11 +107,7 @@ export class BrowserBackend implements Backend {
140107
event = evt;
141108
};
142109
Raven.captureMessage(message);
143-
const normalizedEvent = normalizeRavenEvent(event);
144-
if (normalizedEvent) {
145-
return normalizedEvent;
146-
}
147-
throw new SentryError('Event was undefined when it should be an event');
110+
return event;
148111
} finally {
149112
Raven._sendProcessedPayload = originalSend;
150113
}
@@ -155,7 +118,7 @@ export class BrowserBackend implements Backend {
155118
*/
156119
public async sendEvent(event: SentryEvent): Promise<number> {
157120
return new Promise<number>(resolve => {
158-
sendRavenEvent(prepareEventForRaven(event), error => {
121+
sendRavenEvent(event, error => {
159122
// TODO: Check the response status code
160123
resolve(error ? 500 : 200);
161124
});

packages/browser/test/index.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,10 @@ describe('SentryBrowser', () => {
121121
new BrowserClient({
122122
afterSend: (event: SentryEvent) => {
123123
expect(event.exception).to.not.be.undefined;
124-
expect(event.exception![0]).to.not.be.undefined;
125-
expect(event.exception![0].type).to.equal('Error');
126-
expect(event.exception![0].value).to.equal('test');
127-
expect(event.exception![0].stacktrace).to.not.be.empty;
124+
expect(event.exception!.values[0]).to.not.be.undefined;
125+
expect(event.exception!.values[0].type).to.equal('Error');
126+
expect(event.exception!.values[0].value).to.equal('test');
127+
expect(event.exception!.values[0].stacktrace).to.not.be.empty;
128128
done();
129129
},
130130
dsn,

packages/hub/src/global.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
1-
import { Hub } from './hub';
1+
import { API_VERSION, Hub } from './hub';
22
import { Carrier } from './interfaces';
33

4-
/**
5-
* API compatibility version of this hub.
6-
*
7-
* WARNING: This number should only be incresed when the global interface
8-
* changes a and new methods are introduced.
9-
*/
10-
export const API_VERSION = 2;
11-
124
/** Global interface helper for type safety. */
135
interface Global {
146
__SENTRY__: Carrier;

packages/hub/src/hub.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
import { Breadcrumb, SentryEvent } from '@sentry/types';
2-
import { API_VERSION } from './global';
32
import { Layer } from './interfaces';
43
import { Scope } from './scope';
54

5+
/**
6+
* API compatibility version of this hub.
7+
*
8+
* WARNING: This number should only be incresed when the global interface
9+
* changes a and new methods are introduced.
10+
*/
11+
export const API_VERSION = 2;
12+
613
/**
714
* Internal class used to make sure we always have the latest internal functions
815
* working in case we have a version conflict.

packages/types/src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ export interface SentryEvent {
110110
request?: Request;
111111
modules?: { [key: string]: string };
112112
fingerprint?: string[];
113-
exception?: SentryException[];
113+
exception?: {
114+
values: SentryException[];
115+
};
114116
stacktrace?: Stacktrace;
115117
breadcrumbs?: Breadcrumb[];
116118
contexts?: { [key: string]: object };

tsconfig.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
"baseUrl": "packages",
55
"types": ["node"],
66
"paths": {
7-
"@sentry/*": ["*/src"]
7+
"@sentry/*": ["*/src"],
8+
"raven-js": ["raven-js/src/singleton.js"],
9+
"raven-node": ["raven-node/lib/client.js"]
810
}
911
}
1012
}

0 commit comments

Comments
 (0)