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

Commit

Permalink
馃毃 Fix coding style
Browse files Browse the repository at this point in the history
Related: #28
  • Loading branch information
smolijar committed Nov 22, 2019
1 parent 76d7e5f commit 35199d0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
23 changes: 13 additions & 10 deletions src/sentry.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
import { captureException, captureMessage, Severity, withScope } from '@sentry/node';
import { Transform, TransformCallback } from 'stream';
import { withScope, captureException, captureMessage, Severity } from '@sentry/node';

const reportToSentry = (obj: any) => {
if (!obj.stack) {
return captureMessage(obj.message || obj);
}
const error = new Error(obj.message);
error.message = obj.message;
error.stack = obj.stack;
error.name = obj.name;
return captureException(error);
};

class SentryTransformStream extends Transform {
// tslint:disable-next-line:function-name
Expand All @@ -16,15 +27,7 @@ class SentryTransformStream extends Transform {
withScope(scope => {
scope.setLevel(PINO_TO_SENTRY[obj.level]);
scope.setExtras(obj);
if (obj.stack) {
const error = new Error(obj.message);
error.message = obj.message;
error.stack = obj.stack;
error.name = obj.name;
captureException(error);
} else {
captureMessage(obj.message || obj);
}
reportToSentry(obj);
});
this.push(chunk);
callback();
Expand Down
2 changes: 1 addition & 1 deletion src/streams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import * as util from 'util';
import { loggerNameKey, pkgVersionKey } from '.';
import { AckeeLoggerOptions, AckeeLoggerStream } from './interfaces';
import { levels } from './levels';
import { StackDriverFormatStream } from './stackdriver';
import { SentryTransformStream } from './sentry';
import { StackDriverFormatStream } from './stackdriver';

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

Expand Down

0 comments on commit 35199d0

Please sign in to comment.