From 0c7bd699eb623ce540b7275d5ab9c808642a2393 Mon Sep 17 00:00:00 2001 From: Sven Slootweg Date: Thu, 13 Jul 2017 00:06:11 +0200 Subject: [PATCH] Make error reporting directory configurable --- config.json.example | 3 +++ server.js | 7 ++++--- src/error-reporting.js | 22 +++++++++++----------- 3 files changed, 18 insertions(+), 14 deletions(-) mode change 100644 => 100755 server.js diff --git a/config.json.example b/config.json.example index 8f0e3fa..bfdf6bd 100644 --- a/config.json.example +++ b/config.json.example @@ -5,5 +5,8 @@ "listLimit": 100, "pasteInterval": 1 } + }, + "errors": { + "directory": "./errors" } } diff --git a/server.js b/server.js old mode 100644 new mode 100755 index 8f6cad2..eb07a07 --- a/server.js +++ b/server.js @@ -2,13 +2,14 @@ 'use strict'; -const errorReporter = require("./src/error-reporting"); - +const config = require("./config.json"); const path = require("path"); + +const errorReporter = require("./src/error-reporting")(path.join(__dirname, config.errors.directory)); + const express = require("express"); const expressWs = require("express-ws"); -const config = require("./config.json"); const clientStore = require("./src/client-store")(); const scraper = require("./src/scraper")({ diff --git a/src/error-reporting.js b/src/error-reporting.js index 1e95760..fb08b1c 100644 --- a/src/error-reporting.js +++ b/src/error-reporting.js @@ -4,17 +4,17 @@ const path = require("path"); const reportErrors = require("report-errors"); const mkdirp = require("mkdirp"); -let errorPath = path.join(__dirname, "../errors"); +module.exports = function(errorPath) { + mkdirp.sync(errorPath); -mkdirp.sync(errorPath); + module.exports = reportErrors(errorPath, { + doNotCrash: true, + handler: (error, context) => { + console.error("Unhandled error", error.stack); -module.exports = reportErrors(errorPath, { - doNotCrash: true, - handler: (error, context) => { - console.error("Unhandled error", error.stack); - - if (error.rateLimited !== true) { - process.exit(1); + if (error.rateLimited !== true) { + process.exit(1); + } } - } -}); + }); +};