sveltejs / sveltejs/kit

Check `cause` chain of exceptions when handling redirects

Open
#13,487 0 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

error handling needs-decision
Dominant language
JavaScript
Stars
20.8k
Forks
2.3k
Avg merge
1d 16h
Merged PRs (30d)
156

Description

Describe the problem

Right now, the Connect ES library wraps exceptions thrown inside of calls (including interceptors written by users) into ConnectError, with the original error thrown placed into the cause field. Because of this, when you do a redirect call inside of a connect-es interceptor, it doesn't work as expected.

Describe the proposed solution

Since the cause field is now widely supported, it would be very nice if code that checks for Redirect exceptions could also check the chain of causes.

Alternatives considered
  • An easy-but-cumbersome work-around is to wrap each call to a Connect ES client with a try/catch handler, detect a redirect in the cause and re-throw that. This works today, but it has to be done manually at each RPC call-site, so it is far from ideal.
  • Connect ES could be changed to not wrap errors thrown in interceptors, or make this behavior configurable. However, the sentiment for this change seems to be poor a few different reasons.
Importance

would make my life easier

Additional Information

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating Connect ES redirect handling and the code that checks redirect exceptions. Trace how interceptor errors are wrapped in ConnectError and inspect existing tests around redirects and error causes. Done means redirects are detected through the cause chain, including when errors are nested, with regression coverage for the behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.