1
1
import type { ReadStream } from "fs" ;
2
2
import ApiCall from "./ApiCall" ;
3
3
import Configuration from "./Configuration" ;
4
- import { ImportError } from "./Errors" ;
4
+ import { ImportError , RequestMalformed } from "./Errors" ;
5
5
import { SearchOnlyDocuments } from "./SearchOnlyDocuments" ;
6
6
7
7
// Todo: use generic to extract filter_by values
@@ -388,6 +388,9 @@ export default class Documents<T extends DocumentSchema = object>
388
388
) : Promise < string | ImportResponse [ ] > {
389
389
let documentsInJSONLFormat ;
390
390
if ( Array . isArray ( documents ) ) {
391
+ if ( documents . length === 0 ) {
392
+ throw new RequestMalformed ( "No documents provided" ) ;
393
+ }
391
394
try {
392
395
documentsInJSONLFormat = documents
393
396
. map ( ( document ) => JSON . stringify ( document ) )
@@ -410,6 +413,9 @@ export default class Documents<T extends DocumentSchema = object>
410
413
}
411
414
} else {
412
415
documentsInJSONLFormat = documents ;
416
+ if ( isEmptyString ( documentsInJSONLFormat ) ) {
417
+ throw new RequestMalformed ( "No documents provided" ) ;
418
+ }
413
419
}
414
420
415
421
const resultsInJSONLFormat = await this . apiCall . performRequest < string > (
@@ -514,3 +520,7 @@ export default class Documents<T extends DocumentSchema = object>
514
520
} ) ;
515
521
}
516
522
}
523
+
524
+ function isEmptyString ( str : string | null | undefined ) : boolean {
525
+ return str == null || str === "" || str . length === 0 ;
526
+ }
0 commit comments