mirror of
https://github.com/unraid/api.git
synced 2026-01-19 15:09:40 -06:00
fix: move sentry into correct file
This commit is contained in:
15
app/index.ts
15
app/index.ts
@@ -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);
|
||||
|
||||
|
||||
23
index.js
23
index.js
@@ -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);
|
||||
}
|
||||
Reference in New Issue
Block a user