Skip to content

Commit decfa0e

Browse files
authored
Fix *async* waterfall to spec in this section (#1290)
* Some Code condensing in the process as a result NOTES: * Some of the errors returned may still be strings instead of an Error *(subclassed or not)* so add default conditional for that. Usually those are 400 user errors but could be 500 server error... unknown at this time. Post #1284 #1289 and #1274 #37 Auto-merge
1 parent 76f5a65 commit decfa0e

File tree

1 file changed

+45
-53
lines changed

1 file changed

+45
-53
lines changed

controllers/user.js

+45-53
Original file line numberDiff line numberDiff line change
@@ -1281,35 +1281,25 @@ exports.userGitHubImportScriptPage = function (aReq, aRes, aNext) {
12811281

12821282
// Double check file size.
12831283
if (aBlobUtf8.length > settings.maximum_upload_script_size) {
1284-
aCallback(util.format('File size is larger than maximum (%s bytes).',
1285-
settings.maximum_upload_script_size));
1284+
aCallback(new statusError({
1285+
message: util.format('File size is larger than maximum (%s bytes).',
1286+
settings.maximum_upload_script_size),
1287+
code: 400
1288+
}));
12861289
return;
12871290
}
12881291

12891292
onScriptStored = function (aErr, aScript) {
12901293
if (aErr) {
1291-
statusCodePage(aReq, aRes, aNext, {
1292-
statusCode: aErr.status.code,
1293-
statusMessage: aErr.status.message,
1294-
isCustomView: true,
1295-
statusData: {
1296-
isGHImport: true,
1297-
utf_pathname: githubPathName,
1298-
utf_pathext: githubPathExt,
1299-
user: encodeURIComponent(githubUserId),
1300-
repo: encodeURIComponent(githubRepoName),
1301-
default_branch: encodeURIComponent(githubDefaultBranch),
1302-
path: encodeURIComponent(githubBlobPath)
1303-
}
1304-
});
1294+
aCallback(aErr);
13051295
return;
13061296
}
13071297

13081298
if (!aScript) {
1309-
statusCodePage(aReq, aRes, aNext, {
1310-
statusCode: 500, // NOTE: Watchpoint
1311-
statusMessage: 'Error while importing script.'
1312-
});
1299+
aCallback(new statusError({
1300+
message: 'Error while importing script.',
1301+
code: 500 // NOTE: Watchpoint.
1302+
}));
13131303
return;
13141304
}
13151305

@@ -1345,20 +1335,10 @@ exports.userGitHubImportScriptPage = function (aReq, aRes, aNext) {
13451335
}
13461336
scriptStorage.storeScript(authedUser, blocks, aBlobUtf8, false, onScriptStored);
13471337
} else {
1348-
statusCodePage(aReq, aRes, aNext, {
1349-
statusCode: 400,
1350-
statusMessage: 'Specified file does not contain the proper metadata blocks.',
1351-
isCustomView: true,
1352-
statusData: {
1353-
isGHImport: true,
1354-
utf_pathname: githubPathName,
1355-
utf_pathext: githubPathExt,
1356-
user: encodeURIComponent(githubUserId),
1357-
repo: encodeURIComponent(githubRepoName),
1358-
default_branch: encodeURIComponent(githubDefaultBranch),
1359-
path: encodeURIComponent(githubBlobPath)
1360-
}
1361-
});
1338+
aCallback(new statusError({
1339+
message: 'Specified file does not contain the proper metadata blocks.',
1340+
code: 400
1341+
}));
13621342
return;
13631343
}
13641344

@@ -1390,25 +1370,19 @@ exports.userGitHubImportScriptPage = function (aReq, aRes, aNext) {
13901370
}
13911371
scriptStorage.storeScript(authedUser, blocks, aBlobUtf8, false, onScriptStored);
13921372
} else {
1393-
statusCodePage(aReq, aRes, aNext, {
1394-
statusCode: 400,
1395-
statusMessage: 'Specified file does not contain the proper metadata blocks.',
1396-
isCustomView: true,
1397-
statusData: {
1398-
isGHImport: true,
1399-
utf_pathname: githubPathName,
1400-
utf_pathext: githubPathExt,
1401-
user: encodeURIComponent(githubUserId),
1402-
repo: encodeURIComponent(githubRepoName),
1403-
default_branch: encodeURIComponent(githubDefaultBranch),
1404-
path: encodeURIComponent(githubBlobPath)
1405-
}
1406-
});
1373+
aCallback(new statusError({
1374+
message: 'Specified file does not contain the proper metadata blocks.',
1375+
code: 400
1376+
}));
14071377
return;
14081378
}
14091379

14101380
} else {
1411-
aCallback('Invalid filetype.');
1381+
aCallback(new statusError({
1382+
message: 'Invalid filetype.',
1383+
code: 400
1384+
}));
1385+
return;
14121386
}
14131387
},
14141388
], function (aErr) {
@@ -1420,10 +1394,28 @@ exports.userGitHubImportScriptPage = function (aReq, aRes, aNext) {
14201394
authedUser.name + ' ' + githubUserId + ' ' + githubRepoName + ' ' + githubBlobPath
14211395

14221396
].join('\n'));
1423-
statusCodePage(aReq, aRes, aNext, {
1424-
statusCode: 400,
1425-
statusMessage: aErr
1426-
});
1397+
1398+
if (!(aErr instanceof String)) {
1399+
statusCodePage(aReq, aRes, aNext, {
1400+
statusCode: (aErr instanceof statusError ? aErr.status.code : aErr.code),
1401+
statusMessage: (aErr instanceof statusError ? aErr.status.message : aErr.message),
1402+
isCustomView: true,
1403+
statusData: {
1404+
isGHImport: true,
1405+
utf_pathname: githubPathName,
1406+
utf_pathext: githubPathExt,
1407+
user: encodeURIComponent(githubUserId),
1408+
repo: encodeURIComponent(githubRepoName),
1409+
default_branch: encodeURIComponent(githubDefaultBranch),
1410+
path: encodeURIComponent(githubBlobPath)
1411+
}
1412+
});
1413+
} else {
1414+
statusCodePage(aReq, aRes, aNext, {
1415+
statusCode: 500, // NOTE: Watchpoint
1416+
statusMessage: aErr
1417+
});
1418+
}
14271419
return;
14281420
}
14291421

0 commit comments

Comments
 (0)