|
1 | 1 | // @ts-ignore
|
2 | 2 | import fs from "fs";
|
| 3 | +import "../instrument"; |
3 | 4 | // @ts-ignore
|
4 | 5 | import hapi, {ServerOptions} from "@hapi/hapi";
|
5 | 6 |
|
@@ -40,6 +41,8 @@ import {TranslationLoaderService} from "./services/TranslationLoaderService";
|
40 | 41 | import {WebhookService} from "./services/WebhookService";
|
41 | 42 | import {pluginLog} from "./plugins/logging";
|
42 | 43 |
|
| 44 | +const Sentry = require('@sentry/node'); |
| 45 | + |
43 | 46 | const serverOptions = async (): Promise<ServerOptions> => {
|
44 | 47 | const hasCertificate = config.sslKey && config.sslCert;
|
45 | 48 |
|
@@ -109,11 +112,10 @@ function determineLocal(request: any) {
|
109 | 112 | }
|
110 | 113 |
|
111 | 114 | async function createServer(routeConfig: RouteConfig) {
|
112 |
| - console.log("SERVER CREATING") |
| 115 | + console.log("*** SERVER CREATING WITH PLUGINS ***") |
113 | 116 | const server = hapi.server(await serverOptions());
|
114 | 117 | // @ts-ignore
|
115 | 118 | const {formFileName, formFilePath, options} = routeConfig;
|
116 |
| - |
117 | 119 | if (config.rateLimit) {
|
118 | 120 | await server.register(configureRateLimitPlugin(routeConfig));
|
119 | 121 | }
|
@@ -147,7 +149,10 @@ async function createServer(routeConfig: RouteConfig) {
|
147 | 149 | (request: HapiRequest, h: HapiResponseToolkit) => {
|
148 | 150 | const {response} = request;
|
149 | 151 |
|
150 |
| - if ("isBoom" in response && response.isBoom) { |
| 152 | + if ("isBoom" in response && response.isBoom |
| 153 | + && response?.output?.statusCode >= 500 |
| 154 | + && response?.output?.statusCode < 600) { |
| 155 | + Sentry.captureException(response); |
151 | 156 | return h.continue;
|
152 | 157 | }
|
153 | 158 |
|
@@ -207,6 +212,9 @@ async function createServer(routeConfig: RouteConfig) {
|
207 | 212 | server.state("cookies_policy", {
|
208 | 213 | encoding: "base64json",
|
209 | 214 | });
|
| 215 | + |
| 216 | + // Sentry error monitoring |
| 217 | + await Sentry.setupHapiErrorHandler(server); |
210 | 218 | return server;
|
211 | 219 | }
|
212 | 220 |
|
|
0 commit comments