Skip to content

Commit

Permalink
Reduce : Don't crash if the request is incorrect
Browse files Browse the repository at this point in the history
If the request does not get a number parameter, the server crashes because `undefined.toString()` is undefined. Let's return -1 instead!
  • Loading branch information
TPXP authored Jun 3, 2017
1 parent a8313df commit 53761fb
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion exercises/reduce/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ exercise.addSetup(function (mode, callback) {

this.server = http.createServer(function (req, res) {
var number = url.parse(req.url, true).query.number
res.end((numbers[number]).toString())
if(numbers[number])
return res.end((numbers[number]).toString())
res.end("-1")
})

this.server.listen(9345, callback)
Expand Down

0 comments on commit 53761fb

Please sign in to comment.