-
Notifications
You must be signed in to change notification settings - Fork 1.3k
feat(server$): config argument, optional GET, ServerError #6290
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
Conversation
Deploying qwik-docs with
|
Latest commit: |
fac3aaa
|
Status: | ✅ Deploy successful! |
Preview URL: | https://4077d306.qwik-8nx.pages.dev |
Branch Preview URL: | https://feat-server--options.qwik-8nx.pages.dev |
in another pr I can add 3 levels of config. I also want to do this for better AbortSignal |
This is awesome! 🤩 Would it make sense to have ServerError take a generic argument so any serializable data can be returned? export class ServerError<T = Record<any, any>> extends Error {
constructor(
public status: number,
public data: T
) {
super();
}
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking forward to this!
starters/apps/qwikcity-test/src/routes/(common)/server-func/server-configs/index.tsx
Outdated
Show resolved
Hide resolved
Misko is ok with this API extension |
7ed33f8
to
7c4a973
Compare
import { server$ } from "@builder.io/qwik-city";
import { ServerError } from "@builder.io/qwik-city/middleware/request-handler";
type ResponseTuple = [null | string, string];
const serverFunctionA = server$(async function a(): Promise<ResponseTuple> {
throw new ServerError<[string]>(401, ["my error"]);
});
const serverFunctionB = server$(async function b(): Promise<ResponseTuple> {
return [null, this.method || ""];
});
export const MultipleServerFunctionsInvokedInTask = component$(() => {
const methodA = useSignal("");
const methodB = useSignal("");
useVisibleTask$(async () => {
const [error /*, data */] = await serverFunctionA();
if (error) {
methodA.value = error;
}
await delay(1);
// err, method
const [, method] = await serverFunctionB();
methodB.value = method;
});
return (
<div id="server-error">
{methodA.value}
{methodB.value}
</div>
);
}); |
I'm curious why the error isn't thrown on the client so that it can be caught, and instead we return the error like the method was successful? I'm wondering if this was the right decision for the given reasons:
There is also actually a ErrorResponse class from a routeLoader$, which it might have made sense to reuse so that any API middleware, whether used in a server$ or routeLoader$, can throw the same class and result in the same status code/response handling. I realise this might be late, but with the upcoming v2 changes, would it make sense to revisit this, or is there merit in the way it is currently handled? EDIT |
Overview
fixes #5656
fixes #6288