Forráskód Böngészése

💄 improve error handling and exposure

jmacura 3 éve
szülő
commit
ee05fa0dd2
2 módosított fájl, 37 hozzáadás és 5 törlés
  1. 31 5
      src/app/calculator/calculator.service.ts
  2. 6 0
      src/app/translations.json

+ 31 - 5
src/app/calculator/calculator.service.ts

@@ -3,7 +3,7 @@ import {Injectable} from '@angular/core';
 import {Subject} from 'rxjs';
 import {catchError} from 'rxjs/operators';
 
-import {HsConfig} from 'hslayers-ng';
+import {HsConfig, HsLanguageService, HsToastService} from 'hslayers-ng';
 
 import {FieldService} from './field.service';
 import {ZonesService} from './zones.service';
@@ -31,6 +31,8 @@ export class CalculatorService {
   constructor(
     private fieldService: FieldService,
     private hsConfig: HsConfig,
+    private hsLanguageService: HsLanguageService,
+    private hsToastService: HsToastService,
     private httpClient: HttpClient,
     private zonesService: ZonesService
   ) {
@@ -69,8 +71,7 @@ export class CalculatorService {
         )
         .toPromise();
       this._datesLoading = false;
-      console.log('data received!');
-      console.log(data);
+      console.log('data received!', data);
       this.availableDates = data.dates;
       /* Any previously selected date must be cleaned up
        * so it won't get sent to the API as a wrong param
@@ -78,6 +79,19 @@ export class CalculatorService {
       this.selectedDate = undefined;
     } catch (err) {
       this._datesLoading = false;
+      this.hsToastService.createToastPopupMessage(
+        this.hsLanguageService.getTranslationIgnoreNonExisting(
+          'CALCULATOR',
+          'errorLoading'
+        ),
+        this.hsLanguageService.getTranslationIgnoreNonExisting(
+          'CALCULATOR',
+          'errorLoadingDates'
+        ),
+        {
+          toastStyleClasses: 'bg-warning text-dark',
+        }
+      );
       console.error('Somethin fucked up!');
       console.log(err);
     }
@@ -118,13 +132,25 @@ export class CalculatorService {
           }
         )
         .toPromise();
-      console.log('data received!');
-      console.log(data);
+      console.log('data received!', data);
       this._zonesLoading = false;
       this.zonesService.updateZones(data, {quantileCount: this.quantileCount});
       this.updateImageBackground(this.selectedDate);
     } catch (err) {
       this._zonesLoading = false;
+      this.hsToastService.createToastPopupMessage(
+        this.hsLanguageService.getTranslationIgnoreNonExisting(
+          'CALCULATOR',
+          'errorLoading'
+        ),
+        this.hsLanguageService.getTranslationIgnoreNonExisting(
+          'CALCULATOR',
+          'errorLoadingZones'
+        ),
+        {
+          toastStyleClasses: 'bg-warning text-dark',
+        }
+      );
       console.error('Somethin fucked up!');
       console.log(err);
     }

+ 6 - 0
src/app/translations.json

@@ -4,6 +4,9 @@
       "blurNone": "žádné",
       "getDates": "VYBRAT DATUM",
       "getZones": "ZÍSKAT ZÓNY",
+      "errorLoading": "Chyba při načítání dat",
+      "errorLoadingDates": "Nebylo možné načíst seznam možných dat ze serveru. Zkuste to prosím později.",
+      "errorLoadingZones": "Nebylo možné načíst zóny pole ze serveru. Zkuste to prosím později.",
       "loading": "Načítám",
       "panelHeader": "Výpočet indexů pole",
       "selectBlur": "Chci vyhlazení",
@@ -21,6 +24,9 @@
       "blurNone": "none",
       "getDates": "GET DATES",
       "getZones": "GET ZONES",
+      "errorLoading": "Error loading data",
+      "errorLoadingDates": "It was not possible to load available dates from the server. Please, try again later.",
+      "errorLoadingZones": "It was not possible to load field zones from the server. Please, try again later.",
       "loading": "Loading",
       "panelHeader": "Field calculation",
       "selectBlur": "I want to blur by",