Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 5d32cbea

Přidáno uživatelem Václav Jirák před téměř 6 roky(ů)

Error and information messages modified - correct error messages from backend are displayed and information messages are translated

Zobrazit rozdíly:

webapp/src/app/services/api/basic.service.ts
3 3
import {throwError} from 'rxjs';
4 4
import {environment} from '../../../environments/environment';
5 5
import {MatSnackBar} from '@angular/material';
6

  
6
import {TranslateService} from '@ngx-translate/core';
7 7
@Injectable({
8 8
  providedIn: 'root'
9 9
})
10 10
export class BasicService {
11 11
  protected baseUrl = environment.apiUrl;
12 12

  
13
  constructor(protected http: HttpClient, protected snackBar: MatSnackBar) { }
13
  constructor(protected http: HttpClient, protected snackBar: MatSnackBar, protected translateService: TranslateService) { }
14 14

  
15 15
  protected handleError(error: HttpErrorResponse) {
16
    if (error.error instanceof ErrorEvent) {
17
      console.error('An error occurred:', error.error.message);
16
    let errMsg;
17
    if (!error.error.error) {
18
      this.translateService.get('error.serverCommunication').subscribe((res: string) => {
19
        errMsg = res;
20
      });
18 21
    } else {
19
      console.error(
20
        `Backend returned code ${error.status}, ` +
21
        `body was: ${error.error}`);
22
      errMsg = error.error.message;
22 23
    }
23 24

  
24
    this.snackBar.open('Komunikace se serverem se nezdařila', 'Zavřít');
25
    return throwError(
26
      'Something bad happened; please try again later.');
25
    this.snackBar.open(errMsg, 'X');
26

  
27
    return throwError(errMsg);
27 28
  }
28 29

  
29 30
  /**

Také k dispozici: Unified diff