@edraj/tsdmart 1.0.13 → 1.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.ts +100 -60
  2. package/package.json +1 -1
package/index.ts CHANGED
@@ -327,26 +327,38 @@ export default class Dmart {
327
327
  static baseURL = "http://localhost:8282";
328
328
 
329
329
  public static async login(shortname: string, password: string) {
330
- const {data} = await axios.post<
331
- ApiResponse & { records: Array<LoginResponseRecord> }
332
- >(`${this.baseURL}/user/login`, {shortname, password}, {headers});
333
- return data;
330
+ try {
331
+ const {data} = await axios.post<
332
+ ApiResponse & { records: Array<LoginResponseRecord> }
333
+ >(`${this.baseURL}/user/login`, {shortname, password}, {headers});
334
+ return data;
335
+ } catch (error: any) {
336
+ throw new Error(error.response.data.error)
337
+ }
334
338
  }
335
339
 
336
340
  public static async loginBy(credentials: any, password: string) {
337
- const {data} = await axios.post<
338
- ApiResponse & { records: Array<LoginResponseRecord> }
339
- >(`${this.baseURL}/user/login`, {...credentials, password}, {headers});
340
- return data;
341
+ try {
342
+ const {data} = await axios.post<
343
+ ApiResponse & { records: Array<LoginResponseRecord> }
344
+ >(`${this.baseURL}/user/login`, {...credentials, password}, {headers});
345
+ return data;
346
+ } catch (error: any) {
347
+ throw new Error(error.response.data.error)
348
+ }
341
349
  }
342
350
 
343
351
  public static async logout() {
344
- const {data} = await axios.post<ApiResponse>(
345
- `${this.baseURL}/user/logout`,
346
- {},
347
- {headers}
348
- );
349
- return data;
352
+ try {
353
+ const {data} = await axios.post<ApiResponse>(
354
+ `${this.baseURL}/user/logout`,
355
+ {},
356
+ {headers}
357
+ );
358
+ return data;
359
+ } catch (error: any) {
360
+ throw new Error(error.response.data.error)
361
+ }
350
362
  }
351
363
 
352
364
  public static async create_user(request: any) {
@@ -358,7 +370,7 @@ export default class Dmart {
358
370
  );
359
371
  return data;
360
372
  } catch (error: any) {
361
- return error.response.data;
373
+ throw new Error(error.response.data.error)
362
374
  }
363
375
  }
364
376
 
@@ -371,7 +383,7 @@ export default class Dmart {
371
383
  );
372
384
  return data;
373
385
  } catch (error: any) {
374
- return error.response.data;
386
+ throw new Error(error.response.data.error)
375
387
  }
376
388
  }
377
389
 
@@ -383,7 +395,7 @@ export default class Dmart {
383
395
  );
384
396
  return data;
385
397
  } catch (error: any) {
386
- return null;
398
+ throw new Error(error.response.data.error)
387
399
  }
388
400
  }
389
401
 
@@ -407,7 +419,7 @@ export default class Dmart {
407
419
  }
408
420
  return data;
409
421
  } catch (error: any) {
410
- return null;
422
+ throw new Error(error.response.data.error)
411
423
  }
412
424
  }
413
425
 
@@ -424,8 +436,8 @@ export default class Dmart {
424
436
  {headers, timeout: 3000}
425
437
  );
426
438
  return data;
427
- } catch (e) {
428
- return null;
439
+ } catch (error: any) {
440
+ throw new Error(error.response.data.error)
429
441
  }
430
442
  }
431
443
 
@@ -441,7 +453,7 @@ export default class Dmart {
441
453
  );
442
454
  return data;
443
455
  } catch (error: any) {
444
- return error.response.data;
456
+ throw new Error(error.response.data.error)
445
457
  }
446
458
  }
447
459
 
@@ -454,7 +466,7 @@ export default class Dmart {
454
466
  );
455
467
  return data;
456
468
  } catch (error: any) {
457
- return error.response.data;
469
+ throw new Error(error.response.data.error)
458
470
  }
459
471
  }
460
472
 
@@ -467,7 +479,7 @@ export default class Dmart {
467
479
  );
468
480
  return data;
469
481
  } catch (error: any) {
470
- return error.response.data;
482
+ throw new Error(error.response.data.error)
471
483
  }
472
484
  }
473
485
 
@@ -490,7 +502,7 @@ export default class Dmart {
490
502
  );
491
503
  return data;
492
504
  } catch (error: any) {
493
- throw new Error(error.response.data.error.message)
505
+ throw new Error(error.response.data.error)
494
506
  }
495
507
  }
496
508
 
@@ -530,13 +542,17 @@ export default class Dmart {
530
542
 
531
543
  const headers = {"Content-Type": "multipart/form-data"};
532
544
 
533
- const {data} = await axios.post<ApiResponse>(
534
- `${this.baseURL}/managed/resource_with_payload`,
535
- form_data,
536
- {headers}
537
- );
545
+ try {
546
+ const {data} = await axios.post<ApiResponse>(
547
+ `${this.baseURL}/managed/resource_with_payload`,
548
+ form_data,
549
+ {headers}
550
+ );
538
551
 
539
- return data;
552
+ return data;
553
+ } catch (error: any) {
554
+ throw new Error(error.response.data.error)
555
+ }
540
556
  }
541
557
 
542
558
 
@@ -568,7 +584,7 @@ export default class Dmart {
568
584
  );
569
585
  return data;
570
586
  } catch (error: any) {
571
- return error;
587
+ throw new Error(error.response.data.error)
572
588
  }
573
589
  }
574
590
 
@@ -619,10 +635,14 @@ export default class Dmart {
619
635
  }
620
636
 
621
637
  public static async get_space_health(space_name: string) {
622
- const {data} = await axios.get<
623
- ApiQueryResponse & { attributes: { folders_report: Object } }
624
- >(`${this.baseURL}/managed/health/${space_name}`, {headers});
625
- return data;
638
+ try {
639
+ const {data} = await axios.get<
640
+ ApiQueryResponse & { attributes: { folders_report: Object } }
641
+ >(`${this.baseURL}/managed/health/${space_name}`, {headers});
642
+ return data;
643
+ } catch (error: any) {
644
+ throw new Error(error.response.data.error)
645
+ }
626
646
  }
627
647
 
628
648
  public static async get_attachment_content(
@@ -632,11 +652,15 @@ export default class Dmart {
632
652
  shortname: string,
633
653
  scope: string = "managed"
634
654
  ) {
635
- const {data} = await axios.get<any>(
636
- `${this.baseURL}/${scope}/payload/${resource_type}/${space_name}/${subpath}/${shortname}`,
637
- {headers}
638
- );
639
- return data;
655
+ try {
656
+ const {data} = await axios.get<any>(
657
+ `${this.baseURL}/${scope}/payload/${resource_type}/${space_name}/${subpath}/${shortname}`,
658
+ {headers}
659
+ );
660
+ return data;
661
+ } catch (error: any) {
662
+ throw new Error(error.response.data.error)
663
+ }
640
664
  }
641
665
 
642
666
  public static async get_payload(
@@ -647,11 +671,15 @@ export default class Dmart {
647
671
  ext: string = ".json",
648
672
  scope: string = "managed"
649
673
  ) {
650
- const {data} = await axios.get<any>(
651
- `${this.baseURL}/${scope}/payload/${resource_type}/${space_name}/${subpath}/${shortname}${ext}`,
652
- {headers}
653
- );
654
- return data;
674
+ try {
675
+ const {data} = await axios.get<any>(
676
+ `${this.baseURL}/${scope}/payload/${resource_type}/${space_name}/${subpath}/${shortname}${ext}`,
677
+ {headers}
678
+ );
679
+ return data;
680
+ } catch (error: any) {
681
+ throw new Error(error.response.data.error)
682
+ }
655
683
  }
656
684
 
657
685
  public static async get_payload_content(
@@ -662,11 +690,15 @@ export default class Dmart {
662
690
  ext: string = ".json",
663
691
  scope: string = "managed"
664
692
  ) {
665
- const {data} = await axios.get<any>(
666
- `${this.baseURL}/${scope}/payload/${resource_type}/${space_name}/${subpath}/${shortname}${ext}`,
667
- {headers}
668
- );
669
- return data;
693
+ try {
694
+ const {data} = await axios.get<any>(
695
+ `${this.baseURL}/${scope}/payload/${resource_type}/${space_name}/${subpath}/${shortname}${ext}`,
696
+ {headers}
697
+ );
698
+ return data;
699
+ }catch (error: any) {
700
+ throw new Error(error.response.data.error)
701
+ }
670
702
  }
671
703
 
672
704
  public static async progress_ticket(
@@ -694,7 +726,7 @@ export default class Dmart {
694
726
  );
695
727
  return data;
696
728
  } catch (error: any) {
697
- return error.response.data;
729
+ throw new Error(error.response.data.error)
698
730
  }
699
731
  }
700
732
 
@@ -712,21 +744,29 @@ export default class Dmart {
712
744
  );
713
745
  return data;
714
746
  } catch (error: any) {
715
- return error.response.data;
747
+ throw new Error(error.response.data.error)
716
748
  }
717
749
  }
718
750
 
719
751
  public static async get_manifest() {
720
- const {data} = await axios.get<any>(`${this.baseURL}/info/manifest`, {
721
- headers,
722
- });
723
- return data;
752
+ try {
753
+ const {data} = await axios.get<any>(`${this.baseURL}/info/manifest`, {
754
+ headers,
755
+ });
756
+ return data;
757
+ } catch (error: any) {
758
+ throw new Error(error.response.data.error)
759
+ }
724
760
  }
725
761
 
726
762
  public static async get_settings() {
727
- const {data} = await axios.get<any>(`${this.baseURL}/info/settings`, {
728
- headers,
729
- });
730
- return data;
763
+ try{
764
+ const {data} = await axios.get<any>(`${this.baseURL}/info/settings`, {
765
+ headers,
766
+ });
767
+ return data;
768
+ } catch (error: any) {
769
+ throw new Error(error.response.data.error)
770
+ }
731
771
  }
732
772
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@edraj/tsdmart",
3
- "version": "1.0.13",
3
+ "version": "1.0.14",
4
4
  "description": "A TypeScript implementation of the Dmart that depends on axios.",
5
5
  "author": "Kefah T. Issa",
6
6
  "email": "kefah.issa@gmail.com",