Removing Interceptors from **one** request

Hi. I’m fairly new to all of this and recently i bumped into a problem.

I’m using the aurelia-http-client to make calls to a service and using a interceptor to show a toaster(iziToast) if it receives a “201 created” response.

The problem is: there’s one request that will return a 201, that i dont want to show the toaster.

i could create another httpClient, just for that request, but would be way easier if i could just strip the interceptor away when i createRequest().

is there a way of removing the interceptor from a specific request? kinda like .WithInterceptor(), but like something like .WithoutInterceptors()

2 Likes

An interceptor works along this way:

.withInterceptor({
        request(request) {
          console.log(`Requesting ${request.method} ${request.url}`);
          return request;
        },
        response(response) {
          console.log(`Received ${response.status} ${response.url}`);
          return response;
        }
      });

so as you see you have access to the request/response that happens. Now either one should help you determine which one is the request you want to ditch. In that case just add a conditional if block in order to skip your request.

1 Like

Will this method override the httpClient configuration? because my toaster interceptor is there

1 Like

I think what you need to do is to use this method to put your own interceptor on the httpClient.
Then inside your interceptor, decide whether to call toaster interceptor or not depending on the request / response you receive.

1 Like