Skip to content

Cleanup unnecessary catch clauses #2212

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

Merged
merged 3 commits into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"no-console": 0,
"no-alert": 0,
"no-underscore-dangle": 0,
"no-useless-catch": 2,
"max-len": [1, 120, 2, {"ignoreComments": true, "ignoreTemplateLiterals": true}],
"quote-props": [1, "as-needed"],
"no-unused-vars": [1, {"vars": "local", "args": "none"}],
Expand Down
69 changes: 24 additions & 45 deletions server/scripts/examples-gg-latest.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,20 +121,16 @@ async function getCodePackage() {
}
};

try {
const { data } = await axios.request(options);
data.forEach((metadata) => {
if (
metadata.name.endsWith('P') === true ||
metadata.name.endsWith('M') === true
) {
sketchRootList.push(metadata);
}
});
return sketchRootList;
} catch (err) {
throw err;
}
const { data } = await axios.request(options);
data.forEach((metadata) => {
if (
metadata.name.endsWith('P') === true ||
metadata.name.endsWith('M') === true
) {
sketchRootList.push(metadata);
}
});
return sketchRootList;
}

// 2. get the list of all the top-level sketch directories in P and M
Expand All @@ -155,13 +151,9 @@ function getSketchDirectories(sketchRootList) {
}
};

try {
const { data } = await axios.request(options);
const sketchDirs = flatten(data);
return sketchDirs;
} catch (err) {
throw err;
}
const { data } = await axios.request(options);
const sketchDirs = flatten(data);
return sketchDirs;
})
).then((output) => {
const sketchList = [];
Expand Down Expand Up @@ -193,13 +185,9 @@ function appendSketchItemLinks(sketchList) {
}
};

try {
const { data } = await axios.request(options);
sketches.tree = data;
return sketchList;
} catch (err) {
throw err;
}
const { data } = await axios.request(options);
sketches.tree = data;
return sketchList;
})
);
}
Expand All @@ -220,13 +208,9 @@ function getSketchItems(sketchList) {
}
};

try {
const { data } = axios.request(options);
sketch.data = data;
return sketch;
} catch (err) {
throw err;
}
const { data } = axios.request(options);
sketch.data = data;
return sketch;
}
// pass
})))).then(() => sketchList[0]);
Expand Down Expand Up @@ -422,13 +406,9 @@ function getAllSketchContent(newProjectList) {
};

// console.log("CONVERT ME!")
try {
const { data } = await axios.request(options);
newProject.files[i].content = data;
return newProject;
} catch (err) {
throw err;
}
const { data } = await axios.request(options);
newProject.files[i].content = data;
return newProject;
}
if (newProject.files[i].url) {
return new Promise((resolve, reject) => {
Expand All @@ -444,9 +424,8 @@ function getAllSketchContent(newProjectList) {
resolve(newProject);
});
}
})).catch((err) => {
throw err;
}))).then(() => newProjectList);
}))
)).then(() => newProjectList);
/* eslint-enable */
}

Expand Down
56 changes: 16 additions & 40 deletions server/scripts/examples-ml5.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,9 @@ async function fetchFileContent(item) {
options.url !== null ||
options.url !== ''
) {
try {
const { data } = await axios.request(options);
file.content = data;
} catch (err) {
throw err;
}
const { data } = await axios.request(options);
file.content = data;

// NOTE: remove the URL property if there's content
// Otherwise the p5 editor will try to pull from that url
if (file.content !== null) delete file.url;
Expand All @@ -107,18 +104,13 @@ async function fetchFileContent(item) {
}

/**
* STEP 1: Get the top level cateogories
* STEP 1: Get the top level categories
*/
async function getCategories() {
try {
const options = Object.assign({}, githubRequestOptions);
options.url = `${options.url}/examples/p5js${branchRef}`;
const { data } = await axios.request(options);

return data;
} catch (err) {
return err;
}
const options = Object.assign({}, githubRequestOptions);
options.url = `${options.url}/examples/p5js${branchRef}`;
const { data } = await axios.request(options);
return data;
}

/**
Expand Down Expand Up @@ -170,12 +162,8 @@ async function traverseSketchTree(parentObject) {
const options = Object.assign({}, githubRequestOptions);
options.url = `${options.url}${parentObject.path}${branchRef}`;

try {
const { data } = await axios.request(options);
output.tree = data;
} catch (err) {
throw err;
}
const { data } = await axios.request(options);
output.tree = data;

output.tree = output.tree.map((file) => traverseSketchTree(file));

Expand Down Expand Up @@ -287,12 +275,8 @@ async function getProjectsList() {
const options = Object.assign({}, editorRequestOptions);
options.url = `${options.url}/sketches`;

try {
const { data } = await axios.request(options);
return data.sketches;
} catch (err) {
throw err;
}
const { data } = await axios.request(options);
return data.sketches;
}

/**
Expand All @@ -303,12 +287,8 @@ async function deleteProject(project) {
options.method = 'DELETE';
options.url = `${options.url}/sketches/${project.id}`;

try {
const { data } = await axios.request(options);
return data;
} catch (err) {
throw err;
}
const { data } = await axios.request(options);
return data;
}

/**
Expand All @@ -320,12 +300,8 @@ async function createProject(project) {
options.url = `${options.url}/sketches`;
options.data = project;

try {
const { data } = await axios.request(options);
return data;
} catch (err) {
throw err;
}
const { data } = await axios.request(options);
return data;
}

/**
Expand Down
Loading