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

Interceptor onRequest error #107

Closed
RonSn0w opened this issue Oct 17, 2016 · 12 comments
Closed

Interceptor onRequest error #107

RonSn0w opened this issue Oct 17, 2016 · 12 comments
Labels
Milestone

Comments

@RonSn0w
Copy link

RonSn0w commented Oct 17, 2016

Hello everyone,

I just started using this repository and I seem to be having trouble getting a full response back on a GET operation.

As I understand by following the documentation here once you setup a custom interceptor and properly configure it in your NgModule imports, you should be able to simply replace all instances of your normal Http references with the interceptor.

However what I seem to find is under certain requests the interceptor does not seem to match the same output as the default angular Http request. My custom error interceptor at the moment is a direct copy of the example setup - simply passing along the parameters of the required methods (onRequest, onResponse, and onResponseError). Yet it appears that some of the data is not being propagated through the chain causing my page to no longer load as it was simply using the default angular2 Http module.

Interestingly I'm wondering now if this has any correlation, but the requests that seem to work fine are returning simple values (int) but the one that I know for sure fails is returning a custom json object with multiple values.

Let me know if I can clarify anything further - this library looks awesome and I would love to adopt it! Thanks!

@emoralesb05
Copy link
Contributor

emoralesb05 commented Oct 17, 2016

Hey @RonSn0w,
Its not propagated through the normal ng2 http service, you need to inject and use our HttpInterceptorService which wraps it. Its basically the same usage, just a different http instance.

e.g.

import { Injectable } from '@angular/core';
import { HttpInterceptorService } from '@covalent/http';
@Injectable()
export class CustomService{
  constructor(private _http: HttpInterceptorService) {

  }
}

We just added a layer on top of it to handle interceptors and what not.
Try using it this way and ping us back if it doesnt work. 😄

@RonSn0w
Copy link
Author

RonSn0w commented Oct 17, 2016

Correct @emoralesb05 . What I am saying is if I use the HttpInterceptorService as you have described it seems like the body of the header is not included in the response in the same manner that I am seeing if I simply used angular2's HttpService.

@emoralesb05
Copy link
Contributor

hmm, can you specify more the response you are getting ?

It is kind of weird though since we arent modifying the response at all, its just passing it through the same way we get it back from the ng2 http service. We use this in an internal product with all sorts of responses and havent had any issues.

I want to try and replicate it if possible if we can get more information about this.

@emoralesb05
Copy link
Contributor

If you can post code snippets that would be awesome too.

@RonSn0w
Copy link
Author

RonSn0w commented Oct 17, 2016

Hey @emoralesb05 ,

My colleague and I have appeared to narrow down the issue, and we believe it is due to Observable.forkJoin.

e.g.

 public getData(id: number, version?: number)  {
        return this.interceptor
            .get(actionUrl)
            .map(response => {
                return response.json();
            })
            .catch(this.handleError);
}

Does appear to return the proper data (sorry for misleading you with my earlier statement). However the next step in my code is to get a different source of data in the same manner, and then using the following:

Observable.forkJoin(
            this.service.getData1(this.Id, this.Version),
            this.service.getData2(this.Id)
        )
        .subscribe(response => {
                        console.log("Forked separation!", response);
            this.dataObject1 = response[0];
            this.dataObject2= response[1]; 
        });

I should have a json object with both objects passed along to dataObject1 and dataObject2 respectively on subscribe. Using the interceptor service I am never getting to see the "Forked separation!" log, but if I just used angular2's Http service everything works as expected.

@emoralesb05
Copy link
Contributor

Awesome, ill try and replicate it and see what we can do for this specific scenario.

@emoralesb05 emoralesb05 added this to the Alpha 0.9 milestone Oct 17, 2016
@emoralesb05 emoralesb05 self-assigned this Oct 17, 2016
@emoralesb05
Copy link
Contributor

emoralesb05 commented Oct 18, 2016

Additional question.
Are you using our latest 0.8 release? Because there was an issue fixed for the HttpInterceptorService where we didnt call complete before. #87 was fixed in this release, so i want to discard that if so.

@emoralesb05
Copy link
Contributor

Yep, just tested it with and without the fix (#88) and that was the problem.
Please try updating to covalent 0.8.1 and let us know how it goes 😄.

@RonSn0w
Copy link
Author

RonSn0w commented Oct 18, 2016

Awesome! I started this feat on the 14th and did not notice a newer version yesterday :)

While I do appreciate the fast response time, unfortunately now I can't load my site at all. While using webpack I am receiving a "Uncaught SyntaxError: Unexpected token export" on runtime which points to the index.js file of @covalent/http specifically highlighting the first line (RESTService which I am not currently using).

export { RESTService } from './http-rest.service';
export { HttpInterceptorService } from './http-interceptor.service';
export { CovalentHttpModule } from './http.module';

//# sourceMappingURL=index.js.map



/*****************
 ** WEBPACK FOOTER
 ** ./~/@covalent/http/index.js
 ** module id = 82
 ** module chunks = 0
 **/

@emoralesb05
Copy link
Contributor

emoralesb05 commented Oct 18, 2016

No problem! You have to configure webpack to understand how to load ES6 modules or force it to pick up the http.umd.js file.
Since its not understanding what export means.

@emoralesb05 emoralesb05 removed their assignment Oct 18, 2016
@emoralesb05
Copy link
Contributor

Havent heard anything. Did you test it with our latest and all? 😄

@RonSn0w
Copy link
Author

RonSn0w commented Oct 31, 2016

Sorry for the lack of response! I got distracted with other elements of our project and tabled this until we could find a resolution to the ES6 requirement.

I think we were able to get the module imported and I will be testing today to make sure everything is working, but so far looks good! I'll let you know if I run into any problems and thanks again for being quick to respond! :)

@RonSn0w RonSn0w closed this as completed Oct 31, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants