@@ -422,25 +422,40 @@ export class AtlasUserData<T extends z.Schema> extends IUserData<T> {
422
422
}
423
423
424
424
async readAll ( ) : Promise < ReadAllResult < T > > {
425
- try {
426
- const response = await this . authenticatedFetch ( this . getUrl ( ) , {
427
- method : 'GET' ,
428
- } ) ;
429
- if ( ! response . ok ) {
430
- throw new Error (
425
+ const response = await this . authenticatedFetch ( this . getUrl ( ) , {
426
+ method : 'GET' ,
427
+ } ) ;
428
+ const result : ReadAllResult < T > = {
429
+ data : [ ] ,
430
+ errors : [ ] ,
431
+ } ;
432
+ if ( ! response . ok ) {
433
+ log . error (
434
+ mongoLogId ( 1_001_000_364 ) ,
435
+ 'Atlas Backend' ,
436
+ 'Error reading data' ,
437
+ {
438
+ url : this . getUrl ( ) ,
439
+ error : `Status ${ response . status } ${ response . statusText } ` ,
440
+ }
441
+ ) ;
442
+ result . errors . push (
443
+ new Error (
431
444
`Failed to get data: ${ response . status } ${ response . statusText } `
432
- ) ;
445
+ )
446
+ ) ;
447
+ return result ;
448
+ }
449
+ const json = await response . json ( ) ;
450
+ for ( const item of json ) {
451
+ try {
452
+ const parsedData = this . deserialize ( item . data as string ) ;
453
+ result . data . push ( this . validator . parse ( parsedData ) as z . output < T > ) ;
454
+ } catch ( error ) {
455
+ result . errors . push ( error as Error ) ;
433
456
}
434
- const json = await response . json ( ) ;
435
- const data = Array . isArray ( json )
436
- ? json . map ( ( item ) =>
437
- this . validator . parse ( this . deserialize ( item . data as string ) )
438
- )
439
- : [ ] ;
440
- return { data, errors : [ ] } ;
441
- } catch ( error ) {
442
- return { data : [ ] , errors : [ error as Error ] } ;
443
457
}
458
+ return result ;
444
459
}
445
460
446
461
async updateAttributes (
@@ -463,7 +478,7 @@ export class AtlasUserData<T extends z.Schema> extends IUserData<T> {
463
478
return this . validator . parse ( data ) ;
464
479
} catch ( error ) {
465
480
log . error (
466
- mongoLogId ( 1_001_000_364 ) ,
481
+ mongoLogId ( 1_001_000_365 ) ,
467
482
'Atlas Backend' ,
468
483
'Error updating data' ,
469
484
{
0 commit comments