Skip to content

Commit

Permalink
Add error handling to model requests (#19)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ajbozarth authored Feb 19, 2019
1 parent a03b0c0 commit 99a285f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 6 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion static/js/webapp.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 99a285f

Please sign in to comment.