better API error handling

This commit is contained in:
xfarrow 2024-03-14 15:45:10 +01:00
parent b2abaf7685
commit 35f04d70df
3 changed files with 6 additions and 3 deletions

View File

@ -61,7 +61,7 @@
document.cookie = `token=${data.token};`; document.cookie = `token=${data.token};`;
window.location.href = 'userprofile.html?id=me'; window.location.href = 'userprofile.html?id=me';
} else { } else {
alert(data.error); callbackErrors(data.errors, alert);
} }
} }
</script> </script>

View File

@ -5,7 +5,6 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>Sign Up to Blink</title> <title>Sign Up to Blink</title>
<link rel="stylesheet" href="../css/login-register.css"> <link rel="stylesheet" href="../css/login-register.css">
<script src=""></script>
</head> </head>
<body> <body>
@ -77,7 +76,7 @@
} }
window.location.href = '/login.html'; window.location.href = '/login.html';
} else { } else {
alert(data.error); callbackErrors(data.errors, alert);
} }
}); });
}) })

View File

@ -9,3 +9,7 @@ function getCookie(name) {
} }
return null; return null;
} }
function callbackErrors(errors, func) {
errors.forEach(error => func(error.msg));
}