Skip to content

Commit

Permalink
fix: Return swarm http errors as json
Browse files Browse the repository at this point in the history
Closes ipfs#1176
  • Loading branch information
paulogr authored and JonKrone committed Feb 19, 2018
1 parent d1ce5f6 commit 412f8af
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/http/api/resources/swarm.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,22 @@ exports = module.exports
// common pre request handler that parses the args and returns `addr` which is assigned to `request.pre.args`
exports.parseAddrs = (request, reply) => {
if (!request.query.arg) {
return reply("Argument 'addr' is required").code(400).takeover()
const err = 'Argument \'addr\' is required'
log.error(err)
return reply({
Code: 0,
Message: err
}).code(400).takeover()
}

try {
multiaddr(request.query.arg)
} catch (err) {
return reply("Argument 'addr' is invalid").code(500).takeover()
log.error(err)
return reply({
Code: 0,
Message: err.message
}).code(500).takeover()
}

return reply({
Expand Down

0 comments on commit 412f8af

Please sign in to comment.