Arjix
Arjix
HHono
Created by Phantom on 3/2/2025 in #help
Update the default validator to return custom error response
True, from now on I'll resist posting sub-optimal solutions w/o knowing the experience of the other person
35 replies
HHono
Created by Phantom on 3/2/2025 in #help
Update the default validator to return custom error response
Only to be in more control of the data returned
35 replies
HHono
Created by Phantom on 3/2/2025 in #help
Update the default validator to return custom error response
I'd like to clarify that I am in the process of adding DTOs everywhere to fix this use-case
35 replies
HHono
Created by Phantom on 3/2/2025 in #help
Update the default validator to return custom error response
Sometimes you are left with no choice, and it's good to know all the possible ways of solving smth
35 replies
HHono
Created by Phantom on 3/2/2025 in #help
Update the default validator to return custom error response
If performance and memory is important to you, then it's probably a "bad" solution, bc you are serializing/deserializing and serializing once again the response Other than that, I see no downside
35 replies
HHono
Created by Phantom on 3/2/2025 in #help
Update the default validator to return custom error response
Eh, it's fine really I don't consider it bad, I just know there are better ways of doing it
35 replies
HHono
Created by Phantom on 3/2/2025 in #help
Update the default validator to return custom error response
This may not have been useful for your particular issue since there was a better way, but it is useful if you want to apply transformations to the json response. E.g. I use it to rename all _id to id when returning data from mongodb Should I have used DTOs instead? Yes Am I working on a legacy backend? Also yes, so the least effort solution is the best, unless I want to rewrite a lot of code
35 replies
HHono
Created by Phantom on 3/2/2025 in #help
Update the default validator to return custom error response
Good luck!
35 replies
HHono
Created by Phantom on 3/2/2025 in #help
Update the default validator to return custom error response
Are you freelancing or smth?
35 replies
HHono
Created by Phantom on 3/2/2025 in #help
Update the default validator to return custom error response
I hate clients
35 replies
HHono
Created by Phantom on 3/2/2025 in #help
Update the default validator to return custom error response
Only returning the first error?
35 replies
HHono
Created by griffin on 2/27/2025 in #help
Get the username using basic auth
Can you mark this as solved then?
5 replies
HHono
Created by Phantom on 3/2/2025 in #help
Update the default validator to return custom error response
const errorMiddleware = createMiddleware(async (ctx, next) => {
const ret = await next();

if (ctx.res.status === 400) {
const mimeType = ctx.res.headers.get("Content-Type");
if (mimeType?.starts with("application/json") {
const json = ctx.res.json();
// do stuff
return new Response(ctx.res, {
body; JSON.stringify({})
});
}
}
return ret;
});
const errorMiddleware = createMiddleware(async (ctx, next) => {
const ret = await next();

if (ctx.res.status === 400) {
const mimeType = ctx.res.headers.get("Content-Type");
if (mimeType?.starts with("application/json") {
const json = ctx.res.json();
// do stuff
return new Response(ctx.res, {
body; JSON.stringify({})
});
}
}
return ret;
});
Think of that as pseudocode, because I wrote it on my phone
35 replies
HHono
Created by Phantom on 3/2/2025 in #help
Update the default validator to return custom error response
Easiest way is to just make a global middleware, that looks at the status code, if it is 400, and matches the above structure, replace it with another json
35 replies
HHono
Created by griffin on 2/27/2025 in #help
Get the username using basic auth
looks like you can do auth(ctx.req) to get the info
5 replies
HHono
Created by griffin on 2/27/2025 in #help
Get the username using basic auth
5 replies
HHono
Created by amorfati on 2/27/2025 in #help
correct type of this `Context`
since they are now deleted
21 replies
HHono
Created by amorfati on 2/27/2025 in #help
correct type of this `Context`
I am happy with my warcrimes
21 replies
HHono
Created by amorfati on 2/27/2025 in #help
correct type of this `Context`
No description
21 replies
HHono
Created by amorfati on 2/27/2025 in #help
correct type of this `Context`
I got actual PTSD from that codebase, hacking it to add hono and eventually purge express was so nice
21 replies