elysia
elysia copied to clipboard
onError nomally i can return custom response but now return value dosent work
What version of Elysia.JS is running?
What platform is your computer?
window x64
What steps can reproduce the bug?
it should response back "VALIDATION" right ? but
response back
{
"type": "validation",
"on": "body",
"summary": "Expected string length greater or equal to 7",
"property": "/username",
"message": "Expected string length greater or equal to 7",
"expected": {
"username": " ",
"password": " "
},
"found": {
"username": "aa",
"password": "12345678"
},
"errors": [
{
"summary": "Expected string length greater or equal to 7",
"type": 52,
"schema": {
"maxLength": 12,
"minLength": 7,
"type": "string"
},
"path": "/username",
"value": "aa",
"message": "Expected string length greater or equal to 7"
}
]
}
What is the expected behavior?
"VALIDATION"
What do you see instead?
{ "type": "validation", "on": "body", "summary": "Expected string length greater or equal to 7", "property": "/username", "message": "Expected string length greater or equal to 7", "expected": { "username": " ", "password": " " }, "found": { "username": "aa", "password": "12345678" }, "errors": [ { "summary": "Expected string length greater or equal to 7", "type": 52, "schema": { "maxLength": 12, "minLength": 7, "type": "string" }, "path": "/username", "value": "aa", "message": "Expected string length greater or equal to 7" } ] }
Additional information
i forks from my base-elysia git it work namorlly before update elysiajs because in package.json dependencies.elysia is latest
Hi, I'm unable to reproduce the following code on Elysia 1.1.3 (latest)
new Elysia()
.onError(({ code, error }) => {
if(code === "VALIDATION")
return code
})
.get('/query', () => {
return 'a'
}, {
query: t.Object({
a: t.String()
})
})
.listen(3000)
Can you help provide an example code that may cause this problem?
it happening when add @elysiajs/html
import { Elysia, t } from "elysia";
import { html } from "@elysiajs/html";
const app = new Elysia().use(html()).onError(({ code, error }) => {
if (code === "VALIDATION") {
return code;
}
});
app.get("/", ({ query }) => "hello", { query: t.Object({ a: t.String() }) });
app.listen(3000);
i have same issue with elysia-msgpack plugin, dunno related to plugin or elysia
it happening when add @elysiajs/html
Same here. If I access an endpoint that does not have the elysia/html plugin initialized I get a response back from .onError(), but if it is I do not.
Versions:
- elysia: 1.1.8
- elysia/html: 1.0.2
To reproduce:
const app = new Elysia()
.onError(() => "hi, mark!")
.get("/response", () => {
throw new Error();
})
.use(html())
.get("/no-response", () => {
throw new Error();
});
app.listen({});
LE: If I return "<h1>Hi, Mark!</h1>"; from .onError() I get a response back from the "/no-response" endpoint so I guess there's something to do with the fact that an HTML tag exists in the response.
LLE: If I set autoDetect: false when initializing elysia/html I get a response back, but I am obligated to use ctx.html() when returning a page.
so far I tried these in my onError and get these results:
set.status = 404
return resultTxt
returns content body correctly but with status=200
set.status = 404
throw new NotFoundError(resultTxt)
status and content are ok but content-type=text/plain
return new Response(resultTxt, {
status: 404,
headers: {
'Content-Type': 'text/html'
}
})
status =404 but a default NOT_FOUND text is returned as response body
any help is appreciated, I'm using v1.2.6
Same issue here when using elsyia/html