Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: server$ error handling #7185

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

DustinJSilk
Copy link
Contributor

@DustinJSilk DustinJSilk commented Dec 20, 2024

What is it?

  • Bug

Description

This fixes a few issues with server$ error handling

  • 4xx ServerErrors are returning a a value instead of throwing an error on the frontend
  • server$ middleware could not catch errors - the server$ function would simply exit early. [🐞] server$ middleware cannot catch errors #7183
  • You can now also throw a ServerError in a routeLoader$ to change the status code and return some serialised data. This is simply an added bonus but should pave the way for more standardised errors across loaders, actions, and server$ functions

Checklist

  • My code follows the developer guidelines of this project
  • I performed a self-review of my own code
  • I added a changeset with pnpm change
  • I made corresponding changes to the Qwik docs
  • I added new tests to cover the fix / functionality

@DustinJSilk DustinJSilk requested a review from a team as a code owner December 20, 2024 14:51
Copy link

changeset-bot bot commented Dec 20, 2024

🦋 Changeset detected

Latest commit: 56c29e0

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@builder.io/qwik-city Patch
eslint-plugin-qwik Patch
@builder.io/qwik Patch
create-qwik Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@DustinJSilk
Copy link
Contributor Author

I get this error when running pnpm change: Failed to find where HEAD diverged from origin/upcoming. Does origin/upcoming exist?

@DustinJSilk
Copy link
Contributor Author

I would add a fix for this: #7165, but i have no idea how to fix it.

@DustinJSilk
Copy link
Contributor Author

@wmertens fyi - returning errors as values was intentional in this PR: #6290.
I dont think this was the right decision, as it becomes really difficult to work with. Now, errors behave like javascript errors and the user can catch them and use a type guard on the data instead.

@DustinJSilk
Copy link
Contributor Author

@shairez any chance we can get this PR reviewed?

@wmertens
Copy link
Member

wmertens commented Jan 1, 2025

for the origin/upcoming, try git fetch origin upcoming.

So if I understand correctly, the only somewhat breaking change is that 4xx errors now throw on the client side, right? That seems more like a bugfix than a breaking change.

@DustinJSilk
Copy link
Contributor Author

Thanks @wmertens !

Yes, the only breaking change is that 4xx errors now throw on the client. It should be classified as a bug fix.

I've added a changeset now, I had to temporarily change the changset config "baseBranch": "origin/upcoming", to "baseBranch": "upcoming", to get it to work

Copy link

pkg-pr-new bot commented Jan 5, 2025

Open in Stackblitz

npm i https://pkg.pr.new/@builder.io/qwik@7185
npm i https://pkg.pr.new/@builder.io/qwik-city@7185
npm i https://pkg.pr.new/eslint-plugin-qwik@7185
npm i https://pkg.pr.new/create-qwik@7185

commit: 56c29e0

Copy link
Contributor

github-actions bot commented Jan 5, 2025

built with Refined Cloudflare Pages Action

⚡ Cloudflare Pages Deployment

Name Status Preview Last Commit
qwik-docs ✅ Ready (View Log) Visit Preview 56c29e0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants