Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

Commit 9904a37

Browse files
dignifiedquiredaviddias
authored andcommitted
more fixes
1 parent b560d33 commit 9904a37

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

src/api/block.js

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,29 @@ const streamToValue = require('../stream-to-value')
99
module.exports = (send) => {
1010
return {
1111
get: promisify((args, opts, callback) => {
12-
// TODO this needs to be adjusted with the new go-ipfs http-api
13-
let cid
14-
if (CID.isCID(args)) {
15-
cid = args
16-
args = multihash.toB58String(args.multihash)
17-
} else if (Buffer.isBuffer(args)) {
18-
cid = new CID(args)
19-
args = multihash.toB58String(args)
20-
} else if (typeof args == 'string') {
21-
cid = new CID(args)
22-
} else {
23-
return callback(new Error('invalid argument'))
24-
}
25-
2612
if (typeof opts === 'function') {
2713
callback = opts
2814
opts = {}
2915
}
3016

17+
// TODO this needs to be adjusted with the new go-ipfs http-api
18+
let cid
19+
try {
20+
if (CID.isCID(args)) {
21+
cid = args
22+
args = multihash.toB58String(args.multihash)
23+
} else if (Buffer.isBuffer(args)) {
24+
cid = new CID(args)
25+
args = multihash.toB58String(args)
26+
} else if (typeof args === 'string') {
27+
cid = new CID(args)
28+
} else {
29+
return callback(new Error('invalid argument'))
30+
}
31+
} catch (err) {
32+
return callback(err)
33+
}
34+
3135
// Transform the response from Buffer or a Stream to a Block
3236
const transform = (res, callback) => {
3337
if (Buffer.isBuffer(res)) {

src/request-api.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ function parseError (res, cb) {
1818
if (err) {
1919
return cb(err)
2020
}
21+
2122
if (payload) {
2223
error.code = payload.Code
2324
error.message = payload.Message || payload.toString()

0 commit comments

Comments
 (0)