This repository was archived by the owner on Mar 10, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +19
-14
lines changed Expand file tree Collapse file tree 2 files changed +19
-14
lines changed Original file line number Diff line number Diff line change @@ -9,25 +9,29 @@ const streamToValue = require('../stream-to-value')
9
9
module . exports = ( send ) => {
10
10
return {
11
11
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
-
26
12
if ( typeof opts === 'function' ) {
27
13
callback = opts
28
14
opts = { }
29
15
}
30
16
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
+
31
35
// Transform the response from Buffer or a Stream to a Block
32
36
const transform = ( res , callback ) => {
33
37
if ( Buffer . isBuffer ( res ) ) {
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ function parseError (res, cb) {
18
18
if ( err ) {
19
19
return cb ( err )
20
20
}
21
+
21
22
if ( payload ) {
22
23
error . code = payload . Code
23
24
error . message = payload . Message || payload . toString ( )
You can’t perform that action at this time.
0 commit comments