From 99a285f12e3dceca869cf675951d097b42af6eed Mon Sep 17 00:00:00 2001 From: Alex Bozarth Date: Tue, 19 Feb 2019 13:33:22 -0800 Subject: [PATCH] Add error handling to model requests (#19) As found in #17 the error thrown when the model microservice is unreachable is unreadable and should be handled Now instead of erroring confusingly then dying the error is posted on the console and the user is given a message to check thier microservice This also does not kill the web app since the microservice can be started while the app is running and the app will then use it --- app.js | 7 ++++++- static/js/webapp.js | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app.js b/app.js index 3d0dd46..f6d2dd9 100644 --- a/app.js +++ b/app.js @@ -30,7 +30,12 @@ var app = express(); app.use(express.static('static')); app.all('/model/:route', function(req, res) { - req.pipe(request(args.model + req.path)).pipe(res); + req.pipe(request(args.model + req.path)) + .on('error', function(err) { + console.error(err); + res.status(500).send('Error connecting to the model microservice'); + }) + .pipe(res); }); app.listen(args.port); diff --git a/static/js/webapp.js b/static/js/webapp.js index 56b2bd9..28a1b55 100644 --- a/static/js/webapp.js +++ b/static/js/webapp.js @@ -178,7 +178,7 @@ $(function() { } }, error: function(jqXHR, status, error) { - alert('Object Detection Failed: ' + error); + alert('Object Detection Failed: ' + jqXHR.responseText); }, complete: function() { $('#file-submit').text('Submit');