Skip to content

[rpc] Typing for DetailedError #4954

Description

@Le0Developer

What is the feature you are proposing?

Currently parseResponse throws an DetailedError when the fetch has a non-OK status code.
This error is completely untyped.

I propose the following:

  1. adding a new function like parseResponseWithError which returns an object (similar to how openapi-ts does it):
const { result, error } = await parseResponse(client.hello.$get())
  1. adding a way to force infer a DetailedError (no additional runtime code):
const result = await parseResponse(client.hello.$get()).catch(
  (err: any) => {
    if(err instanceof DetailedError) {
      const e: DetailedError<typeof client.hello.$get> = err;
    }
  }
)

Current workaround, check each possible status code explicitly and then cast the err.data to InferResponseType<typeof client.hello.$get, 4xx>

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request.

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions