|
1 |
| -import { Injectable, OnInit, OnDestroy, Inject } from '@angular/core'; |
| 1 | +import { Injectable, OnDestroy, Inject } from '@angular/core'; |
2 | 2 | import { OidcSecurityService, OpenIdConfiguration, AuthWellKnownEndpoints, AuthorizationResult, AuthorizationState } from 'angular-auth-oidc-client';
|
3 |
| -import { Observable , Subscription } from 'rxjs'; |
| 3 | +import { Observable , Subscription, throwError } from 'rxjs'; |
| 4 | +import { catchError } from 'rxjs/operators'; |
4 | 5 | import { HttpHeaders, HttpClient } from '@angular/common/http';
|
5 | 6 | import { Router } from '@angular/router';
|
6 | 7 |
|
@@ -113,21 +114,37 @@ export class AuthService implements OnDestroy {
|
113 | 114 | }
|
114 | 115 |
|
115 | 116 | get(url: string): Observable<any> {
|
116 |
| - return this.http.get(url, { headers: this.getHeaders() }); |
| 117 | + return this.http.get(url, { headers: this.getHeaders() }) |
| 118 | + .pipe(catchError((error) => { |
| 119 | + this.oidcSecurityService.handleError(error); |
| 120 | + return throwError(error); |
| 121 | + })); |
117 | 122 | }
|
118 | 123 |
|
119 | 124 | put(url: string, data: any): Observable<any> {
|
120 | 125 | const body = JSON.stringify(data);
|
121 |
| - return this.http.put(url, body, { headers: this.getHeaders() }); |
| 126 | + return this.http.put(url, body, { headers: this.getHeaders() }) |
| 127 | + .pipe(catchError((error) => { |
| 128 | + this.oidcSecurityService.handleError(error); |
| 129 | + return throwError(error); |
| 130 | + })); |
122 | 131 | }
|
123 | 132 |
|
124 | 133 | delete(url: string): Observable<any> {
|
125 |
| - return this.http.delete(url, { headers: this.getHeaders() }); |
| 134 | + return this.http.delete(url, { headers: this.getHeaders() }) |
| 135 | + .pipe(catchError((error) => { |
| 136 | + this.oidcSecurityService.handleError(error); |
| 137 | + return throwError(error); |
| 138 | + })); |
126 | 139 | }
|
127 | 140 |
|
128 | 141 | post(url: string, data: any): Observable<any> {
|
129 | 142 | const body = JSON.stringify(data);
|
130 |
| - return this.http.post(url, body, { headers: this.getHeaders() }); |
| 143 | + return this.http.post(url, body, { headers: this.getHeaders() }) |
| 144 | + .pipe(catchError((error) => { |
| 145 | + this.oidcSecurityService.handleError(error); |
| 146 | + return throwError(error); |
| 147 | + })); |
131 | 148 | }
|
132 | 149 |
|
133 | 150 | private getHeaders() {
|
|
0 commit comments