chg: frontend: routes: errorhandling

This commit is contained in:
Alex
2024-10-09 18:07:28 +02:00
parent c008bcad0b
commit 3b3dc9d251
4 changed files with 19 additions and 28 deletions

View File

@@ -44,18 +44,9 @@ export const actions = {
console.log("Login response headers:", Object.fromEntries(res.headers));
if (!res.ok) {
let errorMessage = `HTTP error! status: ${res.status}`;
try {
const errorData = await res.json();
errorMessage = errorData.error || errorMessage;
} catch (parseError) {
console.error("Failed to parse error response:", parseError);
errorMessage = await res.text(); // Get the raw response text if JSON parsing fails
}
console.error("Login failed:", errorMessage);
return fail(res.status, {
errors: [{ error: errorMessage, id: Date.now() }],
});
const errorData = await res.json();
const errors = formatError(errorData.errors);
return fail(res.status, { errors });
}
const responseBody = await res.json();
@@ -81,12 +72,4 @@ export const actions = {
console.log("Redirecting to:", next || "/");
throw redirect(303, next || "/");
},
// if (!res.ok) {
// const response = await res.json();
// const errors = formatError(response.error);
// return fail(400, { errors: errors });
// }
// throw redirect(303, next || "/");
// },
};