Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subscribe result is not working #138

Open
xyrintech opened this issue Apr 9, 2018 · 2 comments
Open

Subscribe result is not working #138

xyrintech opened this issue Apr 9, 2018 · 2 comments

Comments

@xyrintech
Copy link

No description provided.

@tairezzzz
Copy link
Collaborator

@xyrintech Could you provide more details? Maybe simulate your issue on stackblitz?

@baiolo
Copy link

baiolo commented Apr 12, 2018

Hi, I'm also facing troubles with the .subscribe() method, my scenario is:

ngx-restangular is configured as follows:

# Snippet 1

const authRestangular = new Restangular(
          {},
          this.injector,
          this.http
        ).withConfig(restangularConfigurer => {
          restangularConfigurer.setBaseUrl(Costants.BASE_URL);
          restangularConfigurer.setRequestSuffix(Costants.REQUEST_SUFFIX);
          restangularConfigurer.setRequestInterceptor(function (elem, operation) {
            if (operation === 'remove') {
              return null;
            }
            return elem;
          });

          restangularConfigurer.setDefaultHeaders({'Authorization': 'Bearer ' + data.token});
          this.restService.authRestangular = authRestangular;
        });

      },
      error => {
        this.notifier.notify('error', Costants.SHOW_ERROR_LOGIN)
      }

At some point I call:

# Snippet 2

        this.restService.deleteOne({
          service: this.modelService,
          id: this.modelId
        }).subscribe(
          data => {
            this.notifier.notify('success', Costants.SHOW_SUCCESS_DELETE);
            this.modelDeleted.emit(this.modelId);
          },
          error => this.notifier.notify('error', Costants.SHOW_ERROR_DELETE)
        );

The this.restService.deleteOne is doing:

# Snippet 3

  public deleteOne(parameters: { service: any, id: any }) {
    const {service, id} = parameters;
    const resource = this.authRestangular.one(service, id).remove();

    return resource;
  }

With such code I get a weird behaviour: when I call the deleteOne() and the response contains a body (json) and http response code is 200, everything works like a charm.
On the other hand if the response has no body and http status code is 204, the content of the .subscribe() method is not executed.
I found similar problems regarding Restangular but none of the solutions worked for me.

I've tried various configurations for setRequestInterceptor(), and I've also fully reoved it, but no luck.

NOTE: I'm currently using the setRequestInterceptor() suggested in the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants