Skip to content

Commit

Permalink
fix: profile save was always throwing error
Browse files Browse the repository at this point in the history
  • Loading branch information
theClarkSell committed Sep 18, 2023
1 parent a4a9ab7 commit 417a9e2
Showing 1 changed file with 27 additions and 17 deletions.
44 changes: 27 additions & 17 deletions src/routes/(admin my)/my/profiles/primary/+page.server.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,27 +80,37 @@ export const actions = {
}
}

try {
if (isNewProfile) {
if (isNewProfile) {
try {
await createProfile(form.data);
} else {
// these fields cannot be updated.
delete form.data.profileSlug;
delete form.data.isOver13;
delete form.data.acceptedCodeOfConduct;
delete form.data.acceptedTermsOfService;
} catch (error) {
const errorMessage = {
type: 'error',
message: `Whoops!!! ${error.message}`
};

throw redirect(errorMessage, event);
}
} else {
// these fields cannot be updated.
delete form.data.profileSlug;
delete form.data.isOver13;
delete form.data.acceptedCodeOfConduct;
delete form.data.acceptedTermsOfService;

try {
await updateProfile(form.data);
} catch (error) {
const errorMessage = {
type: 'error',
message: `Whoops!!! ${error.message}`
};

throw redirect(errorMessage, event);
}
const message = { type: 'success', message: 'Your system profile has been saved!' };
throw redirect(303, '/', message, event);
} catch (error) {
const errorMessage = {
type: 'error',
message: `Whoops!!! ${error.message}`
};

throw redirect(errorMessage, event);
}

const message = { type: 'success', message: 'Your system profile has been saved!' };
throw redirect(303, '/', message, event);
}
};

0 comments on commit 417a9e2

Please sign in to comment.