Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable Interceptor in exported function?

I use ngx-translator for localization. When I am trying to read json-files with localization that stores in local folder, I receiving an error HttpErrorResponse {headers: HttpHeaders, status: 404, statusText: "Not Found", url: "http:/host.com/api/assets/i18n/en.json", ok: false, …}. I thing that problem is in Interceptor that I use in my app.

// app.module.ts
export function HttpLoaderFactory(http: HttpClient) {
  return new TranslateHttpLoader(http, 'assets/i18n/', '.json');
}

How can I disable interceptor in this function? I tried to set header as X-Skip-Interceptor, but It doesn't help.

like image 798
Joe Kappa Avatar asked Jun 26 '26 22:06

Joe Kappa


1 Answers

You can use HttpBackend

When injected, HttpBackend dispatches requests directly to the backend, without going through the interceptor chain.

In your app.module.ts pass HttpBackend as deps and not HttpClient

TranslateModule.forRoot({
      loader: {
        provide: TranslateLoader,
        useFactory: (HttpLoaderFactory),
        deps: [HttpBackend],
      },
    }),

And Modify HttpLoaderFactory as below

export function HttpLoaderFactory(handler: HttpBackend) {

    const http = new HttpClient(handler);

    return new TranslateHttpLoader(http, './assets/i18n/', '.json');
}
like image 189
Mourice Avatar answered Jun 28 '26 13:06

Mourice



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!