Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
fix: Return swarm http errors as json
Browse files Browse the repository at this point in the history
Closes #1176
  • Loading branch information
paulogr authored and daviddias committed Feb 15, 2018
1 parent 4b79066 commit d3a0ae1
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 d3a0ae1

Please sign in to comment.