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

@@ -90,7 +90,9 @@ export const actions = {
console.dir(formData);
console.dir(cleanUpdateData);
const apiURL = `${BASE_API_URI}/backend/users/update/`;
const res = await fetch(apiURL, {
/** @type {RequestInit} */
const requestUpdateOptions = {
method: "PATCH",
credentials: "include",
headers: {
@@ -98,11 +100,12 @@ export const actions = {
Cookie: `jwt=${cookies.get("jwt")}`,
},
body: JSON.stringify(cleanUpdateData),
});
};
const res = await fetch(apiURL, requestUpdateOptions);
if (!res.ok) {
const response = await res.json();
const errors = formatError(response.error);
const errors = formatError(response.errors);
return fail(400, { errors: errors });
}
@@ -159,7 +162,7 @@ export const actions = {
if (!res.ok) {
const response = await res.json();
const errors = formatError(response.error);
const errors = formatError(response.errors);
return fail(400, { errors: errors });
}
@@ -195,7 +198,7 @@ export const actions = {
if (!res.ok) {
const response = await res.json();
const errors = formatError(response.error);
const errors = formatError(response.errors);
return fail(400, { errors: errors });
}