Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ResourceWrappedError: Resource returned an error that's not an Error instance: [object Object]. #62099

Closed as duplicate of#61861
@TheYoungBeast

Description

@TheYoungBeast

Which @angular/* package(s) are the source of the bug?

core

Is this a regression?

No

Description

rxResource throws an error, handling the error state of an Observable produced by HttpClient.
I provided you with a minimal code to reproduce the error, but think of it as a scenario when a service returns an observable produced by HttpClient.

Please provide a link to a minimal reproduction of the bug

https://lwm3toax.stackblitz.io/

Please provide the exception or error you saw

ERROR Error: Resource is currently in an error state (see Error.cause for details): Resource returned an error that's not an Error instance: [object Object]. Check this error's .cause for the actual error.

ResourceWrappedError: Resource returned an error that's not an Error instance: [object Object]. Check this error's .cause for the actual error.

Error cause: HttpErrorResponse {headers: _HttpHeaders, status: 0, statusText: 'Unknown Error', url: 'https://localhost/non-existing', ok: false, …}

Please provide the environment you discovered this bug in (run ng version)

_                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/
    

Angular CLI: 20.0.2
Node: 22.16.0
Package Manager: npm 10.9.2
OS: linux x64

Angular: 20.0.3
... animations, cdk, common, compiler, compiler-cli, core, forms
... localize, material, platform-browser
... platform-browser-dynamic, router, service-worker

Package                      Version
------------------------------------------------------
@angular-devkit/architect    0.2000.2
@angular-devkit/core         20.0.2
@angular-devkit/schematics   20.0.2
@angular/build               20.0.2
@angular/cli                 20.0.2
@schematics/angular          20.0.2
rxjs                         7.8.2
typescript                   5.8.3
zone.js                      0.15.0

Anything else?

Use this code to reproduce the error:

main.ts:

import {
  ChangeDetectionStrategy,
  Component,
  inject,
  signal,
} from '@angular/core';
import { bootstrapApplication } from '@angular/platform-browser';
import { HttpClient, provideHttpClient } from '@angular/common/http';
import { rxResource } from '@angular/core/rxjs-interop';

@Component({
  selector: 'app-root',
  changeDetection: ChangeDetectionStrategy.OnPush,
  template: `
    Hello world!
    Resource: {{ res.value() }}
  `,
})
export class Playground {
  private readonly httpClient = inject(HttpClient);

  readonly id = signal<number>(0);

  readonly res = rxResource({
    params: this.id,
    stream: ({ params, abortSignal }) =>
      this.httpClient.get('https://localhost/non-existing-'),
    defaultValue: [],
  });
}

bootstrapApplication(Playground, {
  providers: [provideHttpClient()],
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions