Skip to content

Commit 3736f25

Browse files
authored
Merge pull request #2212 from lindapaiste/chore/no-useless-catch
Cleanup unnecessary `catch` clauses
2 parents 3493b3b + dfa9423 commit 3736f25

File tree

5 files changed

+259
-348
lines changed

5 files changed

+259
-348
lines changed

.eslintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"no-console": 0,
2121
"no-alert": 0,
2222
"no-underscore-dangle": 0,
23+
"no-useless-catch": 2,
2324
"max-len": [1, 120, 2, {"ignoreComments": true, "ignoreTemplateLiterals": true}],
2425
"quote-props": [1, "as-needed"],
2526
"no-unused-vars": [1, {"vars": "local", "args": "none"}],

server/scripts/examples-gg-latest.js

Lines changed: 24 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -121,20 +121,16 @@ async function getCodePackage() {
121121
}
122122
};
123123

124-
try {
125-
const { data } = await axios.request(options);
126-
data.forEach((metadata) => {
127-
if (
128-
metadata.name.endsWith('P') === true ||
129-
metadata.name.endsWith('M') === true
130-
) {
131-
sketchRootList.push(metadata);
132-
}
133-
});
134-
return sketchRootList;
135-
} catch (err) {
136-
throw err;
137-
}
124+
const { data } = await axios.request(options);
125+
data.forEach((metadata) => {
126+
if (
127+
metadata.name.endsWith('P') === true ||
128+
metadata.name.endsWith('M') === true
129+
) {
130+
sketchRootList.push(metadata);
131+
}
132+
});
133+
return sketchRootList;
138134
}
139135

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

158-
try {
159-
const { data } = await axios.request(options);
160-
const sketchDirs = flatten(data);
161-
return sketchDirs;
162-
} catch (err) {
163-
throw err;
164-
}
154+
const { data } = await axios.request(options);
155+
const sketchDirs = flatten(data);
156+
return sketchDirs;
165157
})
166158
).then((output) => {
167159
const sketchList = [];
@@ -193,13 +185,9 @@ function appendSketchItemLinks(sketchList) {
193185
}
194186
};
195187

196-
try {
197-
const { data } = await axios.request(options);
198-
sketches.tree = data;
199-
return sketchList;
200-
} catch (err) {
201-
throw err;
202-
}
188+
const { data } = await axios.request(options);
189+
sketches.tree = data;
190+
return sketchList;
203191
})
204192
);
205193
}
@@ -220,13 +208,9 @@ function getSketchItems(sketchList) {
220208
}
221209
};
222210

223-
try {
224-
const { data } = axios.request(options);
225-
sketch.data = data;
226-
return sketch;
227-
} catch (err) {
228-
throw err;
229-
}
211+
const { data } = axios.request(options);
212+
sketch.data = data;
213+
return sketch;
230214
}
231215
// pass
232216
})))).then(() => sketchList[0]);
@@ -422,13 +406,9 @@ function getAllSketchContent(newProjectList) {
422406
};
423407

424408
// console.log("CONVERT ME!")
425-
try {
426-
const { data } = await axios.request(options);
427-
newProject.files[i].content = data;
428-
return newProject;
429-
} catch (err) {
430-
throw err;
431-
}
409+
const { data } = await axios.request(options);
410+
newProject.files[i].content = data;
411+
return newProject;
432412
}
433413
if (newProject.files[i].url) {
434414
return new Promise((resolve, reject) => {
@@ -444,9 +424,8 @@ function getAllSketchContent(newProjectList) {
444424
resolve(newProject);
445425
});
446426
}
447-
})).catch((err) => {
448-
throw err;
449-
}))).then(() => newProjectList);
427+
}))
428+
)).then(() => newProjectList);
450429
/* eslint-enable */
451430
}
452431

server/scripts/examples-ml5.js

Lines changed: 16 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,9 @@ async function fetchFileContent(item) {
7575
options.url !== null ||
7676
options.url !== ''
7777
) {
78-
try {
79-
const { data } = await axios.request(options);
80-
file.content = data;
81-
} catch (err) {
82-
throw err;
83-
}
78+
const { data } = await axios.request(options);
79+
file.content = data;
80+
8481
// NOTE: remove the URL property if there's content
8582
// Otherwise the p5 editor will try to pull from that url
8683
if (file.content !== null) delete file.url;
@@ -107,18 +104,13 @@ async function fetchFileContent(item) {
107104
}
108105

109106
/**
110-
* STEP 1: Get the top level cateogories
107+
* STEP 1: Get the top level categories
111108
*/
112109
async function getCategories() {
113-
try {
114-
const options = Object.assign({}, githubRequestOptions);
115-
options.url = `${options.url}/examples/p5js${branchRef}`;
116-
const { data } = await axios.request(options);
117-
118-
return data;
119-
} catch (err) {
120-
return err;
121-
}
110+
const options = Object.assign({}, githubRequestOptions);
111+
options.url = `${options.url}/examples/p5js${branchRef}`;
112+
const { data } = await axios.request(options);
113+
return data;
122114
}
123115

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

173-
try {
174-
const { data } = await axios.request(options);
175-
output.tree = data;
176-
} catch (err) {
177-
throw err;
178-
}
165+
const { data } = await axios.request(options);
166+
output.tree = data;
179167

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

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

290-
try {
291-
const { data } = await axios.request(options);
292-
return data.sketches;
293-
} catch (err) {
294-
throw err;
295-
}
278+
const { data } = await axios.request(options);
279+
return data.sketches;
296280
}
297281

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

306-
try {
307-
const { data } = await axios.request(options);
308-
return data;
309-
} catch (err) {
310-
throw err;
311-
}
290+
const { data } = await axios.request(options);
291+
return data;
312292
}
313293

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

323-
try {
324-
const { data } = await axios.request(options);
325-
return data;
326-
} catch (err) {
327-
throw err;
328-
}
303+
const { data } = await axios.request(options);
304+
return data;
329305
}
330306

331307
/**

0 commit comments

Comments
 (0)