Skip to content

Commit 99a285f

Browse files
authored
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
1 parent a03b0c0 commit 99a285f

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

app.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,12 @@ var app = express();
3030
app.use(express.static('static'));
3131

3232
app.all('/model/:route', function(req, res) {
33-
req.pipe(request(args.model + req.path)).pipe(res);
33+
req.pipe(request(args.model + req.path))
34+
.on('error', function(err) {
35+
console.error(err);
36+
res.status(500).send('Error connecting to the model microservice');
37+
})
38+
.pipe(res);
3439
});
3540

3641
app.listen(args.port);

static/js/webapp.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ $(function() {
178178
}
179179
},
180180
error: function(jqXHR, status, error) {
181-
alert('Object Detection Failed: ' + error);
181+
alert('Object Detection Failed: ' + jqXHR.responseText);
182182
},
183183
complete: function() {
184184
$('#file-submit').text('Submit');

0 commit comments

Comments
 (0)