@@ -1281,35 +1281,25 @@ exports.userGitHubImportScriptPage = function (aReq, aRes, aNext) {
1281
1281
1282
1282
// Double check file size.
1283
1283
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
+ } ) ) ;
1286
1289
return ;
1287
1290
}
1288
1291
1289
1292
onScriptStored = function ( aErr , aScript ) {
1290
1293
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 ) ;
1305
1295
return ;
1306
1296
}
1307
1297
1308
1298
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
+ } ) ) ;
1313
1303
return ;
1314
1304
}
1315
1305
@@ -1345,20 +1335,10 @@ exports.userGitHubImportScriptPage = function (aReq, aRes, aNext) {
1345
1335
}
1346
1336
scriptStorage . storeScript ( authedUser , blocks , aBlobUtf8 , false , onScriptStored ) ;
1347
1337
} 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
+ } ) ) ;
1362
1342
return ;
1363
1343
}
1364
1344
@@ -1390,25 +1370,19 @@ exports.userGitHubImportScriptPage = function (aReq, aRes, aNext) {
1390
1370
}
1391
1371
scriptStorage . storeScript ( authedUser , blocks , aBlobUtf8 , false , onScriptStored ) ;
1392
1372
} 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
+ } ) ) ;
1407
1377
return ;
1408
1378
}
1409
1379
1410
1380
} else {
1411
- aCallback ( 'Invalid filetype.' ) ;
1381
+ aCallback ( new statusError ( {
1382
+ message : 'Invalid filetype.' ,
1383
+ code : 400
1384
+ } ) ) ;
1385
+ return ;
1412
1386
}
1413
1387
} ,
1414
1388
] , function ( aErr ) {
@@ -1420,10 +1394,28 @@ exports.userGitHubImportScriptPage = function (aReq, aRes, aNext) {
1420
1394
authedUser . name + ' ' + githubUserId + ' ' + githubRepoName + ' ' + githubBlobPath
1421
1395
1422
1396
] . 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
+ }
1427
1419
return ;
1428
1420
}
1429
1421
0 commit comments