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

Commit

Permalink
feat(http): better error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed Nov 11, 2016
1 parent 67fbc0f commit cd7f77d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
18 changes: 13 additions & 5 deletions src/http-api/resources/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ exports = module.exports
// common pre request handler that parses the args and returns `key` which is assigned to `request.pre.args`
exports.parseKey = (request, reply) => {
if (!request.query.arg) {
return reply("Argument 'key' is required").code(400).takeover()
return reply({
Message: "Argument 'key' is required",
Code: 0
}).code(400).takeover()
}

try {
Expand Down Expand Up @@ -127,7 +130,10 @@ exports.get = {
exports.add = {
handler: (request, reply) => {
if (!request.payload) {
return reply('Array, Buffer, or String is required.').code(400).takeover()
return reply({
Message: 'Array, Buffer, or String is required.',
code: 0
}).code(400).takeover()
}

const ipfs = request.server.app.ipfs
Expand Down Expand Up @@ -155,8 +161,10 @@ exports.add = {

parser.on('end', () => {
if (!filesParsed) {
return reply("File argument 'data' is required.")
.code(400).takeover()
return reply({
Message: "File argument 'data' is required.",
code: 0
}).code(400).takeover()
}
fileAdder.end()
})
Expand Down Expand Up @@ -186,7 +194,7 @@ exports.add = {
}).code(500)
}

reply(files.join(''))
reply(files.join('\n'))
.header('x-chunked-output', '1')
.header('content-type', 'application/json')
})
Expand Down
2 changes: 1 addition & 1 deletion src/http-api/resources/swarm.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ exports.connect = {
}).code(500)
}

return reply({
reply({
Strings: [`connect ${addr} success`]
})
})
Expand Down
2 changes: 1 addition & 1 deletion test/http-api/inject/test-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module.exports = (http) => {
url: '/api/v0/cat'
}, (res) => {
expect(res.statusCode).to.equal(400)
expect(res.result).to.be.a('string')
expect(res.result.Message).to.be.a('string')
done()
})
})
Expand Down

0 comments on commit cd7f77d

Please sign in to comment.