Skip to content

Allow extension or overwrite of error handling behaviour to allow custom errors to bubble up #1430

@p-mercury

Description

@p-mercury

Is your feature request related to a problem? Please describe.
I am using the connect RPC client in a Sveltekit applications and on the client transport I have an authentication interceptor. The interceptor manages the access token, adding it to the requests Authorization header if it is valid, but if the token is expired or not present the interceptor throws a redirect error as documented for Sveltekit.

The problem is that currently this redirect error gets converted to a connect error by the setupSignal function which prevents the Sveltekit behaviour of redirecting when this error is detected. This seems like a reasonable use case and is currently not possible.

Describe the solution you'd like
I am not sure what the best way to implement this features is, but two options would be:

  • A transport option to prevent error conversion
  • A transport option that allows you to extend the error handling behaviour

Describe alternatives you've considered
This is the only way I see this currently working, but this defeats the purpose of the interceptor if on every call I need to manually add error handling.

try {
    await client.identity.listAccounts({});
  } catch (err) {
    if (err instanceof ConnectError && isRedirect(err.cause)) {
      throw err.cause;
    }
    throw err;
  }

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions