fix: move sentry into correct file

This commit is contained in:
Alexis Tyler
2020-09-25 10:49:43 +09:30
parent 850c49e852
commit 7164e5810d
2 changed files with 20 additions and 18 deletions

View File

@@ -3,22 +3,10 @@
* Written by: Alexis Tyler
*/
import os from 'os';
import am from 'am';
import * as Sentry from '@sentry/node';
import { core, loadServer } from '@unraid/core';
import { server } from './server';
// Send errors to server if enabled
Sentry.init({
dsn: process.env.SENTRY_DSN,
tracesSampleRate: 1.0,
release: require('../package.json').short(),
environment: process.env.NODE_ENV,
serverName: os.hostname(),
enabled: Boolean(process.env.SENTRY_DSN)
});
// Boot app
am(async () => {
// Load core
@@ -29,9 +17,6 @@ am(async () => {
}, (error: NodeJS.ErrnoException) => {
// We should only end here if core has an issue loading
// Send last exception to Sentry
Sentry.captureException(error);
// Log last error
console.error(error.message);

View File

@@ -1,8 +1,20 @@
// @ts-check
const os = require('os');
const path = require('path');
const Sentry = require('@sentry/node');
const package = require('./package.json');
const { main } = package;
// Send errors to server if enabled
Sentry.init({
dsn: process.env.SENTRY_DSN,
tracesSampleRate: 1.0,
release: require('./package.json').version,
environment: process.env.NODE_ENV,
serverName: os.hostname(),
enabled: Boolean(process.env.SENTRY_DSN)
});
if (!main) {
throw new Error('Missing main field in package.json');
}
@@ -18,6 +30,11 @@ if (process.env.NODE_ENV === 'development') {
}
}
const mainPath = path.resolve(__dirname, main);
require(mainPath);
try {
const mainPath = path.resolve(__dirname, main);
require(mainPath);
} catch (error) {
Sentry.captureException(error);
console.error(error.message);
process.exit(1);
}