File tree 3 files changed +23
-4
lines changed
test/integration/__tests__
3 files changed +23
-4
lines changed Original file line number Diff line number Diff line change 37
37
"localtunnel" : " ^2.0.0" ,
38
38
"nock" : " ^13.0.5" ,
39
39
"p-retry" : " ^4.2.0" ,
40
+ "request" : " ^2.88.2" ,
40
41
"temp" : " ^0.9.1" ,
41
42
"tsd" : " ^0.14.0"
42
43
},
Original file line number Diff line number Diff line change @@ -127,10 +127,18 @@ class TransloaditClient {
127
127
}
128
128
129
129
// Convert uploads to streams
130
- const streamsMap = fromPairs ( Object . entries ( uploads ) . map ( ( [ label , value ] ) => [
131
- label ,
132
- isStream . readable ( value ) ? value : intoStream ( value ) ,
133
- ] ) )
130
+ const streamsMap = fromPairs ( Object . entries ( uploads ) . map ( ( [ label , value ] ) => {
131
+ const isReadable = isStream . readable ( value )
132
+ if ( ! isReadable && isStream ( value ) ) {
133
+ // https://github.com/transloadit/node-sdk/issues/92
134
+ throw new Error ( `Upload named "${ label } " is not a Readable stream` )
135
+ }
136
+
137
+ return [
138
+ label ,
139
+ isStream . readable ( value ) ? value : intoStream ( value ) ,
140
+ ]
141
+ } ) )
134
142
135
143
// Wrap in object structure (so we can know if it's a pathless stream or not)
136
144
const allStreamsMap = fromPairs ( Object . entries ( streamsMap ) . map ( ( [ label , stream ] ) => [ label , { stream } ] ) )
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ const { pipeline: streamPipeline } = require('stream')
15
15
const got = require ( 'got' )
16
16
const pipeline = promisify ( streamPipeline )
17
17
const intoStream = require ( 'into-stream' )
18
+ const request = require ( 'request' )
18
19
19
20
const Transloadit = require ( '../../../src/Transloadit' )
20
21
@@ -260,6 +261,15 @@ describe('API integration', function () {
260
261
} )
261
262
} )
262
263
264
+ it ( 'should throw a proper error for request stream' , async ( ) => {
265
+ const client = createClient ( )
266
+
267
+ const req = request ( genericImg )
268
+
269
+ const promise = client . createAssembly ( { uploads : { file : req } } )
270
+ await expect ( promise ) . rejects . toThrow ( expect . objectContaining ( { message : 'Upload named "file" is not a Readable stream' } ) )
271
+ } )
272
+
263
273
async function testUploadProgress ( isResumable ) {
264
274
const client = createClient ( )
265
275
You can’t perform that action at this time.
0 commit comments