@@ -26,20 +26,21 @@ export class ApiService {
26
26
API_BASE_URL = url ;
27
27
}
28
28
29
- private handleError ( error : HttpErrorResponse , httpMethod : string ) {
29
+ private handleError ( error : HttpErrorResponse , httpMethod : string , url : string ) {
30
30
if ( error . error instanceof ErrorEvent ) {
31
31
console . error ( 'An error occurred:' , error . error . message ) ;
32
32
} else {
33
33
console . error (
34
- `Backend returned code ${ error . status } , method was: ${ httpMethod } , body was: ${ JSON . stringify ( error . error ) } `
34
+ `Backend returned code ${ error . status } , url was: ${ url } method was: ${ httpMethod } , body was: ${ JSON . stringify ( error . error ) } `
35
35
) ;
36
36
}
37
37
return throwError ( error ) ;
38
38
}
39
39
40
40
post ( endpoint : string , body : { } ) : Observable < any > {
41
- return this . http . post ( API_BASE_URL + endpoint , body , httpOptions ) . pipe ( catchError ( error => {
42
- return this . handleError ( error , 'POST' ) ;
41
+ const url = API_BASE_URL + endpoint ;
42
+ return this . http . post ( url , body , httpOptions ) . pipe ( catchError ( error => {
43
+ return this . handleError ( error , 'POST' , url ) ;
43
44
} ) ) ;
44
45
}
45
46
@@ -48,27 +49,31 @@ export class ApiService {
48
49
Object . keys ( apiParams ) . forEach ( key => {
49
50
params = params . set ( key , apiParams [ key ] ) ;
50
51
} ) ;
51
- return this . http . get ( API_BASE_URL + endpoint , { params } ) . pipe ( catchError ( error => {
52
- return this . handleError ( error , 'GET' ) ;
52
+ const url = API_BASE_URL + endpoint ;
53
+ return this . http . get ( url , { params } ) . pipe ( catchError ( error => {
54
+ return this . handleError ( error , 'GET' , url ) ;
53
55
} ) ) ;
54
56
}
55
57
56
58
patch ( endpoint : string , body : { } ) : Observable < any > {
57
- return this . http . patch ( API_BASE_URL + endpoint , body , httpOptions ) . pipe ( catchError ( error => {
58
- return this . handleError ( error , 'PATCH' ) ;
59
+ const url = API_BASE_URL + endpoint ;
60
+ return this . http . patch ( url , body , httpOptions ) . pipe ( catchError ( error => {
61
+ return this . handleError ( error , 'PATCH' , url ) ;
59
62
} ) ) ;
60
63
}
61
64
62
65
put ( endpoint : string , body : { } ) : Observable < any > {
63
- return this . http . put ( API_BASE_URL + endpoint , body , httpOptions ) . pipe ( catchError ( error => {
64
- return this . handleError ( error , 'PUT' ) ;
66
+ const url = API_BASE_URL + endpoint ;
67
+ return this . http . put ( url , body , httpOptions ) . pipe ( catchError ( error => {
68
+ return this . handleError ( error , 'PUT' , url ) ;
65
69
} ) ) ;
66
70
}
67
71
68
72
delete ( endpoint : string , body : { } ) : Observable < any > {
69
73
httpOptions . body = body ;
70
- return this . http . delete ( API_BASE_URL + endpoint , httpOptions ) . pipe ( catchError ( error => {
71
- return this . handleError ( error , 'DELETE' ) ;
74
+ const url = API_BASE_URL + endpoint ;
75
+ return this . http . delete ( url , httpOptions ) . pipe ( catchError ( error => {
76
+ return this . handleError ( error , 'DELETE' , url ) ;
72
77
} ) ) ;
73
78
}
74
79
}
0 commit comments