Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 40f09c7

Browse files
committed
🚨 Fix coding style
Related: #28
1 parent 7fd01cf commit 40f09c7

2 files changed

Lines changed: 14 additions & 11 deletions

File tree

src/sentry.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
1+
import { captureException, captureMessage, Severity, withScope } from '@sentry/node';
12
import { Transform, TransformCallback } from 'stream';
2-
import { withScope, captureException, captureMessage, Severity } from '@sentry/node';
3+
4+
const reportToSentry = (obj: any) => {
5+
if (!obj.stack) {
6+
return captureMessage(obj.message || obj);
7+
}
8+
const error = new Error(obj.message);
9+
error.message = obj.message;
10+
error.stack = obj.stack;
11+
error.name = obj.name;
12+
return captureException(error);
13+
};
314

415
class SentryTransformStream extends Transform {
516
// tslint:disable-next-line:function-name
@@ -16,15 +27,7 @@ class SentryTransformStream extends Transform {
1627
withScope(scope => {
1728
scope.setLevel(PINO_TO_SENTRY[obj.level]);
1829
scope.setExtras(obj);
19-
if (obj.stack) {
20-
const error = new Error(obj.message);
21-
error.message = obj.message;
22-
error.stack = obj.stack;
23-
error.name = obj.name;
24-
captureException(error);
25-
} else {
26-
captureMessage(obj.message || obj);
27-
}
30+
reportToSentry(obj);
2831
});
2932
this.push(chunk);
3033
callback();

src/streams.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import * as util from 'util';
66
import { loggerNameKey, pkgVersionKey } from '.';
77
import { AckeeLoggerOptions, AckeeLoggerStream } from './interfaces';
88
import { levels } from './levels';
9-
import { StackDriverFormatStream } from './stackdriver';
109
import { SentryTransformStream } from './sentry';
10+
import { StackDriverFormatStream } from './stackdriver';
1111

1212
const pkgJson = JSON.parse(fs.readFileSync(path.resolve(path.join(__dirname, '..', 'package.json')), 'utf8'));
1313

0 commit comments

Comments
 (0)