-
-
Notifications
You must be signed in to change notification settings - Fork 234
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
set.status isn't working #415
Comments
@mvolkmann can you provide more information to reproduce the issue? I created a similar code and it's working as expected even with different code numbers here is my code: const app = new Elysia()
.get("/", () => "Hello Elysia")
.post("/account", ({ body, set }: any) => {
const { email, password } = body;
const goodEmail = validEmail(email);
const goodPassword = validPassword(password);
const good = goodEmail && goodPassword;
set.status = good ? 200 : 416;
console.log("/account: set.status =", set.status);
return {html: good ? 'A new account was created.' : ''};
})
.listen(3000); and here is my request fetch('http://localhost:3000/account', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
email: 'some email',
}),
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error)); I noticed you are returning an html, are you using something to parse that html response? |
In my case the request is coming from the browser using htmx. Htmx takes that HTML response and inserts it into the DOM. It doesn't seem though that htmx has any impact on this because I see in the DevTools Network tab that a POST request is sent and the response status is 200 even though I log on the server that it is 400. |
I just tried changing my endpoint to return a string instead of HTML. |
@mvolkmann it looks like a bug on elysia-html package I found a similar issue on their repository you can check there |
Oh I am experiencing the same issue. Is there a workaround? elysiaContext.set.status = 404
console.log(elysiaContext)
return
// set: {
// headers: {},
// status: 404,
// }, I am not returning html however. |
Unable to reproduce in the latest Elysia version, closing as complete. If the problem still persists, feel free to reopen the issue. Thanks. |
I have this endpoint definition that sets
set.status
to 400 and logs that it does so.But the actual response status I see in Chrome DevTools is always 200.
Am I doing something wrong?
The text was updated successfully, but these errors were encountered: