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

Commit a73902b

Browse files
start fixing small issues with the new object api
1 parent 0a33a61 commit a73902b

File tree

1 file changed

+56
-9
lines changed

1 file changed

+56
-9
lines changed

src/api/object.js

+56-9
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ module.exports = (send) => {
1616
if (!options) {
1717
options = {}
1818
}
19-
multihash = cleanMultihash(multihash, options)
19+
20+
try {
21+
multihash = cleanMultihash(multihash, options)
22+
} catch (err) {
23+
return callback(err)
24+
}
2025

2126
send('object/get', multihash, null, null, (err, result) => {
2227
if (err) {
@@ -105,14 +110,23 @@ module.exports = (send) => {
105110
if (!options) {
106111
options = {}
107112
}
108-
multihash = cleanMultihash(multihash, options)
113+
114+
try {
115+
multihash = cleanMultihash(multihash, options)
116+
} catch (err) {
117+
return callback(err)
118+
}
109119

110120
send('object/data', multihash, null, null, (err, result) => {
111121
if (err) {
112122
return callback(err)
113123
}
114124

115-
result.pipe(bl(callback))
125+
if (typeof result.pipe === 'function') {
126+
result.pipe(bl(callback))
127+
} else {
128+
callback(null, result)
129+
}
116130
})
117131
}),
118132
links: promisify((multihash, options, callback) => {
@@ -123,7 +137,12 @@ module.exports = (send) => {
123137
if (!options) {
124138
options = {}
125139
}
126-
multihash = cleanMultihash(multihash, options)
140+
141+
try {
142+
multihash = cleanMultihash(multihash, options)
143+
} catch (err) {
144+
return callback(err)
145+
}
127146

128147
send('object/links', multihash, null, null, (err, result) => {
129148
if (err) {
@@ -148,7 +167,12 @@ module.exports = (send) => {
148167
if (!options) {
149168
options = {}
150169
}
151-
multihash = cleanMultihash(multihash, options)
170+
171+
try {
172+
multihash = cleanMultihash(multihash, options)
173+
} catch (err) {
174+
return callback(err)
175+
}
152176

153177
send('object/stat', multihash, null, null, callback)
154178
}),
@@ -175,7 +199,12 @@ module.exports = (send) => {
175199
if (!options) {
176200
options = {}
177201
}
178-
multihash = cleanMultihash(multihash, options)
202+
203+
try {
204+
multihash = cleanMultihash(multihash, options)
205+
} catch (err) {
206+
return callback(err)
207+
}
179208

180209
send('object/patch/add-link', [multihash, dLink.name, bs58.encode(dLink.hash).toString()], null, null, (err, result) => {
181210
if (err) {
@@ -192,7 +221,12 @@ module.exports = (send) => {
192221
if (!options) {
193222
options = {}
194223
}
195-
multihash = cleanMultihash(multihash, options)
224+
225+
try {
226+
multihash = cleanMultihash(multihash, options)
227+
} catch (err) {
228+
return callback(err)
229+
}
196230

197231
send('object/patch/rm-link', [multihash, dLink.name], null, null, (err, result) => {
198232
if (err) {
@@ -209,7 +243,12 @@ module.exports = (send) => {
209243
if (!options) {
210244
options = {}
211245
}
212-
multihash = cleanMultihash(multihash, options)
246+
247+
try {
248+
multihash = cleanMultihash(multihash, options)
249+
} catch (err) {
250+
return callback(err)
251+
}
213252

214253
send('object/patch/set-data', [multihash], null, data, (err, result) => {
215254
if (err) {
@@ -226,7 +265,12 @@ module.exports = (send) => {
226265
if (!options) {
227266
options = {}
228267
}
229-
multihash = cleanMultihash(multihash, options)
268+
269+
try {
270+
multihash = cleanMultihash(multihash, options)
271+
} catch (err) {
272+
return callback(err)
273+
}
230274

231275
send('object/patch/append-data', [multihash], null, data, (err, result) => {
232276
if (err) {
@@ -262,6 +306,9 @@ function cleanMultihash (multihash, options) {
262306
} else {
263307
throw new Error('not valid multihash')
264308
}
309+
} else if (!multihash) {
310+
throw new Error('missing valid multihash')
265311
}
312+
266313
return multihash
267314
}

0 commit comments

Comments
 (0)