Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: profile save was always throwing error #66

Merged
merged 1 commit into from
Sep 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
};