1 |
41741550
|
Hung Hoang
|
import { Injectable } from '@angular/core';
|
2 |
|
|
import {HttpClient, HttpErrorResponse, HttpHeaders} from '@angular/common/http';
|
3 |
|
|
import {throwError} from 'rxjs';
|
4 |
b919891c
|
Hung Hoang
|
import {environment} from '../../environments/environment';
|
5 |
41741550
|
Hung Hoang
|
|
6 |
|
|
@Injectable({
|
7 |
|
|
providedIn: 'root'
|
8 |
|
|
})
|
9 |
|
|
export class BasicService {
|
10 |
b919891c
|
Hung Hoang
|
protected baseUrl = environment.apiUrl;
|
11 |
41741550
|
Hung Hoang
|
protected withResponse = {
|
12 |
|
|
headers: new HttpHeaders({
|
13 |
|
|
observe: 'response',
|
14 |
|
|
})
|
15 |
|
|
};
|
16 |
|
|
|
17 |
|
|
protected handleError(error: HttpErrorResponse) {
|
18 |
|
|
if (error.error instanceof ErrorEvent) {
|
19 |
|
|
console.error('An error occurred:', error.error.message);
|
20 |
|
|
} else {
|
21 |
|
|
console.error(
|
22 |
|
|
`Backend returned code ${error.status}, ` +
|
23 |
|
|
`body was: ${error.error}`);
|
24 |
|
|
}
|
25 |
|
|
return throwError(
|
26 |
|
|
'Something bad happened; please try again later.');
|
27 |
|
|
}
|
28 |
|
|
|
29 |
|
|
constructor(protected http: HttpClient) { }
|
30 |
|
|
}
|