Skip to content

Type for useQuery error dosen't cover unexpected errors #2151

Open
@ludwighogstrom

Description

@ludwighogstrom

openapi-react-query version

0.3.0

Description

The type of the error returned by useQuery and queryOptions is determined by the "paths" specification. For example:

const {data, error} = useQuery(queryClient.queryOptions("get", "/my-path"));

In this case, error is typed as:

{ error_code: number } | null

That object matches the API response when an expected error occurs.

However, if something unexpected goes wrong—such as fetch throwing TypeError: Failed to fetch—the typing no longer aligns. In this case, the error is not an object with an error_code property but a FetchError instead.

An unexpected response can also occur if the API is temporarily down and fails to return a response in the expected format.

Reproduction

Block the request in Chrome DevTools and log the error. You'll see that the error is a TypeError: Failed to fetch, rather than the expected format defined by the API specification.

Instruction how to block request https://developer.chrome.com/docs/devtools/network-request-blocking

Expected result

The typing of error should be something else. Maybe unknown?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingopenapi-react-queryRelevant to openapi-react-query

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions