-
Notifications
You must be signed in to change notification settings - Fork 12
/
index.js
42 lines (38 loc) · 921 Bytes
/
index.js
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
41
42
'use strict';
const fp = require('fastify-plugin');
const base = require('./lib/base');
const request = require('./lib/request');
const validate = require('./lib/validate');
const {
getTransactionName,
extractRequestData,
extractUserData,
errorResponse,
shouldHandleError,
} = require('./utils');
const DEFAULT_CONFIG = {
setErrorHandler: true,
shouldHandleError,
errorResponse,
getTransactionName,
extractRequestData,
extractUserData,
skipInit: false,
};
const fastifySentry = function (fastify, opts, next) {
const config = Object.assign({}, DEFAULT_CONFIG, opts);
try {
validate(config);
} catch (error) {
return next(error);
}
base(fastify, config);
request(fastify);
next();
};
module.exports = fp(fastifySentry, {
name: '@immobiliarelabs/fastify-sentry',
fastify: '4.x',
});
module.exports.default = fastifySentry;
module.exports.fastifySentry = fastifySentry;