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};`;
window.location.href = 'userprofile.html?id=me';
} else {
alert(data.error);
callbackErrors(data.errors, alert);
}
}
</script>

View File

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

View File

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