I have to apply a descriptografia
on the body of the return of a request via Interceptor
, however the decryption method is asynchronous and returns a promisse
.
Here's an excerpt from the class:
intercept(req: HttpRequest, next: HttpHandler): Observable> {
return next.handle(req).pipe(map((event: HttpEvent<any>) => {
if (event instanceof HttpResponse) {
let _body;
this.cryptMethod.decrypt(event.body).this(res => _body = res); // Método assíncrono
return event.clone({ body: JSON.parse(_body) });
}
return event;
}));
}'
It happens that this.cryptMethod.decrypt()
is asynchronous, so the return is reached before the _body is filled in.
Is there a solution to this?