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

Commit 9763f86

Browse files
fix(http:object): proper handling of empty args
1 parent 6d82408 commit 9763f86

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

src/http-api/resources/object.js

+15-8
Original file line numberDiff line numberDiff line change
@@ -351,11 +351,21 @@ exports.patchAddLink = {
351351
return reply("Arguments 'root', 'name' & 'ref' are required").code(400).takeover()
352352
}
353353

354+
const error = (msg) => reply({
355+
Message: msg,
356+
Code: 0
357+
}).code(500).takeover()
358+
359+
if (!request.query.arg[0]) {
360+
return error('cannot create link with no root')
361+
}
362+
354363
if (!request.query.arg[1]) {
355-
return reply({
356-
Message: 'cannot create link with no name!',
357-
Code: 0
358-
}).code(500).takeover()
364+
return error('cannot create link with no name!')
365+
}
366+
367+
if (!request.query.arg[2]) {
368+
return error('cannot create link with no ref')
359369
}
360370

361371
try {
@@ -366,10 +376,7 @@ exports.patchAddLink = {
366376
})
367377
} catch (err) {
368378
log.error(err)
369-
return reply({
370-
Message: 'invalid ipfs ref path',
371-
Code: 0
372-
}).code(500).takeover()
379+
return error('invalid ipfs ref path')
373380
}
374381
},
375382

0 commit comments

Comments
 (0)