Keycloak-angular: Promise never gets called

Created on 3 Jan 2018  路  8Comments  路  Source: mauriciovigolo/keycloak-angular

When using the HttpClient Observable.toPromise() the promise is never called.

Workaround: Do not use toPromise(), but subscribe on the Observable instead.

Bug

Most helpful comment

Hello @Herbis and @mleegwt,

Just released version v.1.2.3 with the bug fix. Thank you for sharing your time to help the library!

All 8 comments

Hello @mleegwt,

The library doesn't have Observable.toPromise(). Could you share the method or an example with the problems you are facing?

Also, the versions of angular and keycloak-library are important.

Thanks!

Observed using version 1.1.1. In combination with RXJS library that provides Observable and Promise.

@mleegwt,

Could you share the keycloak-angular method you are having problem?

Hi @mleegwt ,

I will close this issue since it doesn't appear to be a bug in the library and more the way to use the Observable subscribe from the rxjs library. There is no .toPromise in the keycloak-angular library.

If there is anything I can help you, please contact me or send the lib method you are calling that is happing the error.

Thanks

Hey @mauriciovigolo ,
I have actually run into the same problem as @mleegwt it seems.

So usually, my requests look like this:

import {HttpClient, HttpParams} from "@angular/common/http";
.....
return this.httpClient.get(url, {params: params})
      .toPromise()
      .then((response: string) => {
        console.log(response);
        return new Date(response);
      }).catch(reason => {
        console.log(reason);
        return new Date();
      });

where the Observable.toPromise() is getting called to handle responses as a Promise.
In the end, the call itself is successful, but "then" of the promise never gets called. "catch" however is being called, if an invalid request is made.
I have no idea what exactly is causing the issue, but it must be the interceptor, because this started happening (or rather - not happening) after I setup keycloak-angular.

Meanwhile, this works as a workaround:

return new Promise<Date>(resolve => {
      let subscription = this.httpClient.get(url, {params: params}).subscribe((value: string) => {
      resolve(new Date(value));
      subscription.unsubscribe();
    })});

Thanks for creating this library by the way, it's really handy. Hopefully the problem is solvable.

Hello @Herbis,

Thanks for your example and now think I get it. This could also be related to issue #8 , I will take a look on it.

Sorry for the delay to reply your message, I'm on vacation theses days, but I'll fix and release a new version.

Thank you again and it's rewarding to know that the library is benefiting you and your projects.

@Herbis: Thanks for the clear example.
@mauriciovigolo : Sorry for my lack of respone. The example is exactly what I would provide.

Hello @Herbis and @mleegwt,

Just released version v.1.2.3 with the bug fix. Thank you for sharing your time to help the library!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ValentinBossi picture ValentinBossi  路  4Comments

jdmaguire picture jdmaguire  路  3Comments

jderuere picture jderuere  路  4Comments

czeckd picture czeckd  路  4Comments

pahlers picture pahlers  路  3Comments