Skip to main content
cngx-src documentation

cngxAsyncInterceptor

Interceptor

Functional interceptor

projects/common/data/async-registry/http-interceptor.ts

Import#

import { cngxAsyncInterceptor } from '@cngx/common/data'

Description#

Functional HTTP interceptor that surfaces every in-flight HttpRequest in the ambient CngxAsyncRegistry, so isAnythingLoading() aggregates raw HTTP traffic alongside explicit component states.

Fully opt-in and self-contained:

  • Resolves inject(CngxAsyncRegistry, { optional: true }) and passes the request straight through when no registry is provided - zero behaviour change for consumers who do not opt in.
  • Passes through without registering when CNGX_ASYNC_SKIP is set.
  • Otherwise registers a fresh createManualState (set loading) under a per-request uid, maps the final response / error onto it, and unregisters in a finalize that fires on success and error (and on unsubscribe), so a request can never pin the global loading state.

Per-request uid identity (from CngxAsyncRegistry) means concurrent requests sharing a label never evict one another - completing one leaves the other tracked. The interceptor does not swallow errors: setError records the failure, then the error propagates to the caller unchanged.