Skip to content

Commit

Permalink
PLAT-14359 added better error messages and a check for if no patch bo…
Browse files Browse the repository at this point in the history
…dy value is detected
  • Loading branch information
robester0403 committed Apr 4, 2024
1 parent cdaf7bc commit 1179dce
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions scripts/setModuleDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,24 @@ export const setModuleDetails = async (
if (acceptanceCriteria) {
patchBody.acceptance_criteria = acceptanceCriteria;
}

if (Object.keys(patchBody).length === 0) {
invalid("No module details was provided to update. Did you mean to include a value?");
return;
}
const patchSpinner = ora(
"Updating module details."
).start();

try {
const patchResponse = await apiClient.patch({
path: `/v1/catalog/module/${id}`,
body: patchBody
});
const patchResponse = await apiClient.patch({
path: `/v1/catalog/module/${id}`,
body: patchBody
}).then(patchSpinner.stop());

if (patchResponse.ok) {
patchSpinner.stop();
valid(`Module details updated for ${id}.`);
} else {
patchSpinner.stop();
invalid(`Unable to update module details for ${id}. Please try again.`);
}
} catch (error) {
invalid(`An error occurred: ${error.message}. Please try again.`);
if (patchResponse.ok) {
valid(`Module details updated for ${id}.`);
} else if (patchResponse.status === 404) {
invalid(`Cannot find requested module with id ${id}.`);
} else {
invalid("Unable to update modules details. Please try again later.");
}
};

0 comments on commit 1179dce

Please sign in to comment.