enhance error handling for register

This commit is contained in:
2026-01-26 20:28:25 +01:00
parent 8fe362c966
commit 0e9fedc9b4
2 changed files with 55 additions and 0 deletions

View File

@@ -15,6 +15,9 @@ export default (router, tpl) => {
const { username, password, password_confirm, token } = req.post;
const renderError = (msg) => {
if (req.headers['x-requested-with'] === 'XMLHttpRequest' || (req.headers.accept && req.headers.accept.includes('application/json'))) {
return res.writeHead(200, { 'Content-Type': 'application/json' }).end(JSON.stringify({ success: false, msg }));
}
return res.reply({
body: tpl.render("register", { theme: req.cookies.theme ?? "f0ck", error: msg })
});