-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSentryError.js
More file actions
40 lines (33 loc) · 1010 Bytes
/
SentryError.js
File metadata and controls
40 lines (33 loc) · 1010 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
require("dotenv").config();
const Sentry = require("@sentry/node");
const { version } = require("./package.json");
// eslint-disable-next-line no-unused-vars
const Tracing = require("@sentry/tracing");
const { name } = require("./package.json");
// initialises Sentry
Sentry.init({
dsn: process.env.SENTRY_ENDPOINT,
release: name + "@" + version,
environment: process.env.NODE_ENV,
});
class SentryError extends Error {
constructor(errMessage, data, type = "error") {
// Passes errMessage to the Error super class,
// similar to call new Error(errMessage).
super(errMessage);
// Maintains proper stack trace for where our error was thrown (only available on V8)
if (Error.captureStackTrace) {
Error.captureStackTrace(this, SentryError);
}
this.name = "SentryError";
Sentry.addBreadcrumb({
category: "data",
message: errMessage,
data: data,
type: type,
level: Sentry.Severity.Debug,
});
Sentry.captureException(errMessage);
}
}
module.exports = { SentryError };