BACK TO BLOG
SIGNALS 19 NOV 2026 · 9 MIN READ

Chain Angular resources without losing the real error

Chain-dependent HTTP requests with Angular’s httpResource and chain(). See how loading and errors propagate, why a 404 can show up as “Dependency error,” and how to recover the original HTTP error

Ali Gamal

Front-End Tech Lead · Angular Architect · AI Tool Builder


// QUICK REACTIONS

Enjoyed this article? Leave a signal without writing a comment.

ALI GAMAL · >_ alidevhub logo

TL;DR

  • chain() lets one resource wait on another. Loading and error states flow downstream by themselves.
  • Case 1, upstream succeeds: the downstream params get the real value and the request fires.
  • Case 2, upstream fails: the downstream resource errors too, but error() is a ResourceDependencyError that says only “Dependency error”. The real HTTP error is on .cause.
  • Unwrap it with a computed and bind that in the template. Don’t print error()?.message.
  • I checked the behavior against Angular 22.2.4 and ran both cases in a browser.

A downstream resource that fails should still tell you why.

I had two resources. The first loads a user. The second loads a joke, using the user’s id. The second one can’t start until the first one is done.

Without chain(), the obvious move is to read userResource.value() inside params. That works, but it hides what the first resource is doing. While the first one loads, the second one sits idle instead of loading. If the first one fails, value() throws, and the second one ends up with a generic ResourceValueError instead of a clear dependency error.

This post walks through the demo I built for it, the two cases you’ll hit on day one, and the traps after that.

The setup

Two httpResource calls. The second one reads the first through chain:

protected readonly randomId = signal(Math.floor(Math.random() * 20) + 1);

jsonPlaceholderResource = httpResource<JsonPlaceholderUser>(() => {
  return `https://jsonplaceholder.typicode.com/users/${this.randomId()}`;
});

jokesResource = httpResource<Joke>(({ chain }) => {
  const user = chain(this.jsonPlaceholderResource);
  return user?.id ? `https://v2.jokeapi.dev/joke/Any?safe-mode&idRange=${user.id}-${user.id + 20}` : undefined;
});

The id is random between 1 and 20. That’s on purpose. jsonplaceholder only has users 1 to 10, so about half of the page loads end in a 404. I wanted the error case to show up without any mocking.

chain comes from the context object that params receives.[1] Its type in @angular/core is <T>(resource: Resource<T>) => T. It returns the upstream value only when the upstream is resolved or local. In every other state it throws, and the thrown value moves your resource into the matching state.

I read the implementation in 22.2.4 to get the exact mapping:

Upstream status What chain() does Downstream status
idle throws ResourceParamsStatus.IDLE idle
loading throws ResourceParamsStatus.LOADING loading, loader doesn’t run
reloading throws ResourceParamsStatus.LOADING loading, no stale value
error throws ResourceDependencyError error
resolved or local returns value() your params keep running

The source is _resource-chunk.mjs in @angular/core. The docs say the same thing in plain words.[2]

Case 1: the upstream succeeds

Open the page and get an id from 1 to 10. Say 10.

Here is what the network tab shows, in order:

GET https://jsonplaceholder.typicode.com/users/10          200
GET https://v2.jokeapi.dev/joke/Any?safe-mode&idRange=10-30       200

The second request only starts after the first one lands. Until then jokesResource.status() is loading, even though its own request hasn’t been sent. The status pill in the demo shows that. Then it flips to resolved and the joke card renders.

Nothing to wire up here. That’s the point of chain.

Case 2: the upstream fails, and the message lies

Now click Reload until the id is above 10. I got 17.

The network tab has one request:

GET https://jsonplaceholder.typicode.com/users/17          404

The joke API is never called. That’s correct. chain threw, so params never produced a URL.

The status pill says error, so the propagation works. The problem is the message. My template did this:

@else if (jokesResource.error()) {
  <p>{{ jokesResource.error()?.message }}</p>
}

And the card showed:

Error occurred while fetching the joke.
Dependency error

“Dependency error”. Nothing about a 404, nothing about user 17.

Why it says that

jokesResource.error() isn’t the HTTP error. It’s the wrapper chain threw. This is Angular’s own class, simplified from the 22.2.4 source. You don’t write it; you import it from @angular/core:

class ResourceDependencyError extends Error {
  constructor(dependency) {
    super('Dependency error', { cause: dependency.error() });
    this.name = 'ResourceDependencyError';
    this.dependency = dependency;
  }
}

The message is a fixed string. The real error is on .cause, and the upstream resource itself is on .dependency. When a thrown value is already an Error, Angular keeps it as it is, so that wrapper is exactly what error() gives you.

The class is exported from @angular/core, so instanceof works.

The fix, from the template side

Don’t print .message. Unwrap the cause in a computed, and bind that:

import { computed, ResourceDependencyError } from '@angular/core';
import { HttpErrorResponse } from '@angular/common/http';

protected readonly errorMessage = computed(() => {
  const err = this.jokesResource.error();
  if (err instanceof ResourceDependencyError) {
    const cause = err.cause;
    if (cause instanceof HttpErrorResponse) {
      return `HTTP ${cause.status} from ${cause.url}`;
    }
    return cause instanceof Error ? cause.message : String(cause);
  }
  return err?.message;
});
<p>{{ errorMessage() }}</p>

Two details matter here.

  • cause is typed unknown. With strictTemplates on, jokesResource.error()?.cause?.message won’t compile. A computed with a type guard is the clean way to narrow it.
  • HttpErrorResponse isn’t an Error at runtime. The type declares implements Error, but the class extends HttpResponseBase. So cause instanceof Error is false for a 404, and a lazy fallback would print [object Object]. Check for HttpErrorResponse first.

I print the status and the URL, not statusText. In my Chrome run statusText was “Unknown Error” for the 404, not “Not Found”. “HTTP 404 from https://jsonplaceholder.typicode.com/users/17” reads better.

After the fix, the same id shows:

Error occurred while fetching the joke.
HTTP 404 from https://jsonplaceholder.typicode.com/users/17

Don’t read the user-facing message from error()?.message on a chained resource. You’ll get “Dependency error” for every upstream failure, whatever the cause.

There’s also a spec for it. It flushes a 404 on the user request and asserts the important parts: the status is error, the error is a ResourceDependencyError with the message “Dependency error”, the cause is not an Error instance, and no joke request was made.


More cases worth knowing

The upstream reloads

Call jsonPlaceholderResource.reload() on a resolved chain. I did this in the browser through ng.getComponent:

Moment Upstream Downstream
Before resolved resolved
During reloading loading
After resolved resolved

During the reload, the downstream hasValue() was false and value() was undefined. The joke disappears while the upstream reloads. The docs call this out: during reloading, chain doesn’t return the previously resolved value.[2:1] If your UI flashes empty on every refresh, that’s why.

The Reload button in my demo changes the id instead of calling reload(). So the upstream goes loading, not reloading. The downstream behaves the same either way.

The upstream resolves, but the value is undefined

chain returns whatever value() holds. If that’s undefined, user?.id is undefined, the whole params returns undefined, and the resource goes idle. My jokesResource handles it by returning undefined when there’s no id.

Traps in params

  • Wrapping in an object. The docs warn about params: ({chain}) => ({companyId: chain(user)?.companyId}). That object is always defined, so the loader runs with an undefined id. Pass the chained value directly.[2:2] For httpResource the same trap is a template string. `/users/${user?.id}` is a defined string, so you’d request /users/undefined. Return undefined instead, like the demo does.
  • Most throws become the error. In 22.2.4, anything thrown in params that isn’t one of the two status codes ends up as the resource’s error, except the one case in the next bullet. It isn’t only chain doing this.
  • Creating a resource inside params throws for real. It raises RuntimeError 992, “Cannot create a resource inside the params of another resource”. Angular rethrows that one instead of turning it into an error state.

chain vs .value() vs computed

You can read userResource.value() inside params directly. The docs say to avoid it. While the upstream loads, returning undefined makes the downstream go idle instead of loading. If the upstream fails, value() throws a ResourceValueError. chain mirrors the real loading and error states.[2:3]

But chain is only for the case where the downstream does its own async work. If you just derive a value from a resource, with no second request, use computed.

Keeping the old value while it reloads

If the empty flash bothers you, resourceFromSnapshots can wrap a resource and keep the previous value during loading. The docs show a withPreviousValue helper built on linkedSignal.[2:4]

resourceFromSnapshots is marked experimental in the docs. I haven’t wired it into this demo, so I’m only pointing at it, not vouching for it.


What I’d take from this

  • Let chain carry the status. Don’t hand-roll idle and loading checks across two resources. The cost is that you must know the mapping, so keep the table above close.
  • Never show error()?.message for a chained resource. It’s always “Dependency error”. Unwrap .cause in a computed. The cost is one small function per chained resource.
  • Narrow with HttpErrorResponse, not Error. It doesn’t extend Error, so the usual guard fails on HTTP errors.
  • Return undefined, not a URL built from undefined. That’s how a chained resource stays idle instead of firing a bad request.
  • Test the 404 path. The spec that came with the demo timed out in beforeEach, because it called whenStable() with no HTTP testing backend. The new one uses HttpTestingController and covers both cases.

Sources


ALI GAMAL · Tech Lead · Front-End Architecture · Angular

Written by Ali Gamal. More at alidevhub.com and blog.alidevhub.com.

GitHub @Arigatouz · X @AliDevEgy · LinkedIn alidevegy · Bluesky @arigatouz.bsky.social · dev.to arigatouz


  1. Angular API reference for ResourceParamsContext: https://angular.dev/api/core/ResourceParamsContext#chain ↩︎

  2. Angular docs, Async reactivity with resources, Chaining resources: https://angular.dev/guide/signals/resource#chaining-resources ↩︎ ↩︎ ↩︎ ↩︎ ↩︎

// QUICK REACTIONS

Enjoyed this article? Leave a signal without writing a comment.


// DISCUSSION

Reader Comments (0)

Register or log in to leave a comment.

// NO COMMENTS YET