question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ServerDataSource with HttpClien inteceptor

See original GitHub issue

I’m using HttpClient and i have Interceptor to insert headers as token etc. How can i work with ServerDataSource and HttpClient through my interceptor? I tried base test (without interceptor) as

constructor(
        http: HttpClient,
    ) {
        this.source = new ServerDataSource( http, { endPoint: 'https://site.here/black_listed_client?_page=1&_limit=50&_order=DESC&_sort=id' } );
    }

It shows an error:

Argument of type ‘HttpClient’ is not assignable to parameter of type ‘Http’. Property ‘_backend’ is missing in type ‘HttpClient’.

Also when im set _page=1&_limit=100 its ignored and im my request it looks like

?_order=DESC&_sort=id&_page=1&_limit=100&_page=1&_limit=10 It automatically added last 2 params as page=1 and limit=10

Now about work with interceptor. all my requests looks like Service

 public getInfo(url:string): Observable<any>{
      return this.http.get(url);
  }

request

this.scoringService.getInfo('/scoring/stoplists/black_listed_client').subscribe(value => {
                // value - результат
                this.source = JSON.parse(value);
            },
interceptor
 intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
        const url = '/';
        req = req.clone({
            url: url + req.url,
            responseType: 'text',
            headers: req.headers.set('Authorization', this.sessionStorage.retrieve('access_token'))
        });
........
}

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
dvirHamcommented, Jan 4, 2018

It works with the Http (angular/http) library and not HttpClient (so far).

0reactions
anshumansworldcommented, Sep 5, 2018

declare interceptor in your module as well:

{
  provide: HTTP_INTERCEPTORS,
  useClass: TokenInterceptor, // Your Interceptor class
  multi: true
}

This should also be added in your module where you are using smart table.

Read more comments on GitHub >

github_iconTop Results From Across the Web

HttpClient Request intercepter like, at time of getting response ...
Something like this: @Injectable() export class I1 implements HttpInterceptor { constructor(public service: SomeService) ...
Read more >
Insider's guide into interceptors and HttpClient mechanics in ...
Here I'll dig deeper into internal mechanics of the HttpClient service and ... For each interceptor we declare a class that implements intercept...
Read more >
Pattern-Oriented Software Architecture, Patterns for ... - X-Files
The Interceptor architectural pattern (109) allows services to be added to a framework transparently and to be triggered automatically when certain events ...
Read more >
Kuali Rice 2.2.0-M1 Release Notes - Directory listing for /
inject a serverDataSource into the CoreConfigurer which would point to your Kuali ... [KULRICE-5340] - Determine why CXF Interceptor to enforce immutable ...
Read more >
Intro to Angular Http Interceptors - Ultimate Courses
Interceptors allow us to “intercept” incoming (or outgoing) HTTP requests using the HttpClient . By intercepting an HTTP request, we can modify ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found