Skip to content

Angular: caught errors in the queryFn do not run in the zone #8839

Closed
@JoepKockelkorn

Description

@JoepKockelkorn

Describe the bug

I'm experiencing weird behaviour when using the throwOnError: true setting as the default in the QueryClient options. When an error occurs that is not handled via the template because of throwOnError: true, then the error should be caught by the Angular ErrorHandler. This somehow does not happen on first pageload.

As discussed in this discord question, a working fix could be to catch synchronous errors that happen inside of the runOutsideAngular callback in create-base-query.ts and trigger the NgZone.onError.emit function manually as proposed here.

Your minimal, reproducible example

https://github.com/JoepKockelkorn/tanstack-angular-throw-on-error-bug

Steps to reproduce

See the README of the repro github repo.

Expected behavior

The ErrorHandler.handleError is called on initial pageload.

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

MacOS 15.3 (24D60)
Browser: Brave Version 1.76.74 Chromium: 134.0.6998.89 (Official Build) (arm64)

Tanstack Query adapter

angular-query

TanStack Query version

5.69.0

TypeScript version

5.7.2

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions