From bf9c9d0a0d36a50027a206a68bfd964928d16464 Mon Sep 17 00:00:00 2001 From: Michael Cinkus Date: Thu, 23 Feb 2017 16:20:47 -0600 Subject: [PATCH] Return an error page for the blocked users. Changed the returned status code from 429 to 403. This is to better reflect the functionality of a blocklist rather than rate limiting which 429 implies. Signed-off-by: Michael Cinkus --- index.js | 5 ++- templates/blocklist.status.js | 57 +++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 templates/blocklist.status.js diff --git a/index.js b/index.js index 703fe07..7c64baf 100644 --- a/index.js +++ b/index.js @@ -60,8 +60,11 @@ const testHandler = (req, res) => { // Abort if user is blocked if (blockList.indexOf(req.params.user) !== -1) { ErrorHandler.log(`Request blocked for user ${req.params.user}`) + + const template = require(__dirname + '/templates/blocklist.status.js') + const blockListTemplate = template(req) - return res.status(429).send() + return res.status(blockListTemplate.statusCode).send(blockListTemplate.body) } const speedtracker = new SpeedTracker({ diff --git a/templates/blocklist.status.js b/templates/blocklist.status.js new file mode 100644 index 0000000..d124f7d --- /dev/null +++ b/templates/blocklist.status.js @@ -0,0 +1,57 @@ +const utils = require(__dirname + '/../lib/utils') + +const blocklist = (req) => { + const body = ` + + + + + 403 Forbidden! + + + +
+
+

ERROR 403 - Forbidden!

+
+
+

The following error occurrred:

+

Requests for user ${req.params.user} are blocked.

+
+

If you believe this is an error or would like to dispute this block then contact: abuse@speedtracker.org

+
+
+ + + ` + + return { + body, + statusCode: 403 + } +} + +module.exports = blocklist