From b6542a78c14b3d2e350b6620272a88094abda1c1 Mon Sep 17 00:00:00 2001 From: Noah Loomans Date: Thu, 15 Dec 2016 14:13:43 +0100 Subject: add user frendly error handling --- routes/meetingpointProxy.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'routes') diff --git a/routes/meetingpointProxy.js b/routes/meetingpointProxy.js index cec74a8..b2b51c9 100644 --- a/routes/meetingpointProxy.js +++ b/routes/meetingpointProxy.js @@ -1,16 +1,17 @@ var express = require('express') var router = express.Router() -const Promise = require('bluebird') -const request = Promise.promisify(require('request')) -const encoding = require('encoding') +const request = require('request') /* GET home page. */ router.get('/:url', function (req, res, next) { - request(`http://www.meetingpointmco.nl/${req.params.url}`) - .then(raw => raw.body) - .then(page => encoding.convert(page, 'UTF-8', 'Windows-1252')) - .then(body => { res.end(body) }) - .catch(next) + const url = `http://www.meetingpointmco.nl/${req.params.url}` + request(url, function (err, data) { + if (err) { + next(err) + return + } + res.status(data.statusCode).end(data.body) + }) }) module.exports = router -- cgit v1.1