Projekt

Obecné

Profil

Stáhnout (1.02 KB) Statistiky
| Větev: | Tag: | Revize:
1
import {Injectable} from '@angular/core';
2
import {HttpClient, HttpErrorResponse, HttpParams} from '@angular/common/http';
3
import {throwError} from 'rxjs';
4
import {environment} from '../../environments/environment';
5

    
6
@Injectable({
7
  providedIn: 'root'
8
})
9
export class BasicService {
10
  protected baseUrl = environment.apiUrl;
11

    
12
  constructor(protected http: HttpClient) { }
13

    
14
  protected handleError(error: HttpErrorResponse) {
15
    if (error.error instanceof ErrorEvent) {
16
      console.error('An error occurred:', error.error.message);
17
    } else {
18
      console.error(
19
        `Backend returned code ${error.status}, ` +
20
        `body was: ${error.error}`);
21
    }
22
    return throwError(
23
      'Something bad happened; please try again later.');
24
  }
25

    
26
  protected createParams(params: any) {
27
    let httpParams = new HttpParams();
28
    for (const key in params) {
29
      if (params.hasOwnProperty(key)) {
30
        if (params[key] != null) {
31
          httpParams = httpParams.set(key, params[key]);
32
        }
33
      }
34
    }
35

    
36
    return httpParams;
37
  }
38
}
(1-1/9)