I'm calling an endpoint which needs an authentication on the server.
/users/:userId/my/endpoint => getData(): Observable<any>
The server responds with an error, if the authentication is expired. Then i'm able to refresh this authentication with a client secret i'm sending by POST
/refresh/me => refreshAuth(): Observable<any>
After that, i'll send the first request again and get a successful response (happy case).
How can i achieve this with a single Observable? I know, there is for example catchError
and retry
.
getData()
.pipe(
catchError(e => {
if (error.code === 1224) {
return refreshAuth();
}
return throwError(error);
}),
retry(1)
).subscribe();
But this would retry every error case, right? How can i retry the whole chain once on the specific auth expired case?