@@ -16,7 +16,12 @@ module.exports = (send) => {
16
16
if ( ! options ) {
17
17
options = { }
18
18
}
19
- multihash = cleanMultihash ( multihash , options )
19
+
20
+ try {
21
+ multihash = cleanMultihash ( multihash , options )
22
+ } catch ( err ) {
23
+ return callback ( err )
24
+ }
20
25
21
26
send ( 'object/get' , multihash , null , null , ( err , result ) => {
22
27
if ( err ) {
@@ -105,14 +110,23 @@ module.exports = (send) => {
105
110
if ( ! options ) {
106
111
options = { }
107
112
}
108
- multihash = cleanMultihash ( multihash , options )
113
+
114
+ try {
115
+ multihash = cleanMultihash ( multihash , options )
116
+ } catch ( err ) {
117
+ return callback ( err )
118
+ }
109
119
110
120
send ( 'object/data' , multihash , null , null , ( err , result ) => {
111
121
if ( err ) {
112
122
return callback ( err )
113
123
}
114
124
115
- result . pipe ( bl ( callback ) )
125
+ if ( typeof result . pipe === 'function' ) {
126
+ result . pipe ( bl ( callback ) )
127
+ } else {
128
+ callback ( null , result )
129
+ }
116
130
} )
117
131
} ) ,
118
132
links : promisify ( ( multihash , options , callback ) => {
@@ -123,7 +137,12 @@ module.exports = (send) => {
123
137
if ( ! options ) {
124
138
options = { }
125
139
}
126
- multihash = cleanMultihash ( multihash , options )
140
+
141
+ try {
142
+ multihash = cleanMultihash ( multihash , options )
143
+ } catch ( err ) {
144
+ return callback ( err )
145
+ }
127
146
128
147
send ( 'object/links' , multihash , null , null , ( err , result ) => {
129
148
if ( err ) {
@@ -148,7 +167,12 @@ module.exports = (send) => {
148
167
if ( ! options ) {
149
168
options = { }
150
169
}
151
- multihash = cleanMultihash ( multihash , options )
170
+
171
+ try {
172
+ multihash = cleanMultihash ( multihash , options )
173
+ } catch ( err ) {
174
+ return callback ( err )
175
+ }
152
176
153
177
send ( 'object/stat' , multihash , null , null , callback )
154
178
} ) ,
@@ -175,7 +199,12 @@ module.exports = (send) => {
175
199
if ( ! options ) {
176
200
options = { }
177
201
}
178
- multihash = cleanMultihash ( multihash , options )
202
+
203
+ try {
204
+ multihash = cleanMultihash ( multihash , options )
205
+ } catch ( err ) {
206
+ return callback ( err )
207
+ }
179
208
180
209
send ( 'object/patch/add-link' , [ multihash , dLink . name , bs58 . encode ( dLink . hash ) . toString ( ) ] , null , null , ( err , result ) => {
181
210
if ( err ) {
@@ -192,7 +221,12 @@ module.exports = (send) => {
192
221
if ( ! options ) {
193
222
options = { }
194
223
}
195
- multihash = cleanMultihash ( multihash , options )
224
+
225
+ try {
226
+ multihash = cleanMultihash ( multihash , options )
227
+ } catch ( err ) {
228
+ return callback ( err )
229
+ }
196
230
197
231
send ( 'object/patch/rm-link' , [ multihash , dLink . name ] , null , null , ( err , result ) => {
198
232
if ( err ) {
@@ -209,7 +243,12 @@ module.exports = (send) => {
209
243
if ( ! options ) {
210
244
options = { }
211
245
}
212
- multihash = cleanMultihash ( multihash , options )
246
+
247
+ try {
248
+ multihash = cleanMultihash ( multihash , options )
249
+ } catch ( err ) {
250
+ return callback ( err )
251
+ }
213
252
214
253
send ( 'object/patch/set-data' , [ multihash ] , null , data , ( err , result ) => {
215
254
if ( err ) {
@@ -226,7 +265,12 @@ module.exports = (send) => {
226
265
if ( ! options ) {
227
266
options = { }
228
267
}
229
- multihash = cleanMultihash ( multihash , options )
268
+
269
+ try {
270
+ multihash = cleanMultihash ( multihash , options )
271
+ } catch ( err ) {
272
+ return callback ( err )
273
+ }
230
274
231
275
send ( 'object/patch/append-data' , [ multihash ] , null , data , ( err , result ) => {
232
276
if ( err ) {
@@ -262,6 +306,9 @@ function cleanMultihash (multihash, options) {
262
306
} else {
263
307
throw new Error ( 'not valid multihash' )
264
308
}
309
+ } else if ( ! multihash ) {
310
+ throw new Error ( 'missing valid multihash' )
265
311
}
312
+
266
313
return multihash
267
314
}
0 commit comments