diff --git a/static.js b/static.js index 69397e4d..39932534 100644 --- a/static.js +++ b/static.js @@ -18,10 +18,21 @@ const mime = require('mime-types'); // one megabyte openwhisk limit + 20% Base64 inflation + safety padding const REDIRECT_LIMIT = 750000; +function errorCode(code) { + switch (code) { + case 400: + return 404; + default: + return code; + } +} + function error(message, code = 500) { + // treat + const statusCode = errorCode(code); console.error('delivering error', message, code); return { - statusCode: code, + statusCode, headers: { 'Content-Type': 'text/html', 'X-Static': 'Raw/Static', @@ -129,13 +140,7 @@ function deliverPlain(owner, repo, ref, entry, root) { 'X-Static': 'Raw/Static', }, }; - }).catch((rqerror) => { - console.error('REQUEST FAILED', rqerror.response.body.toString()); - if (rqerror.statusCode === 404) { - return error(rqerror.response.body.toString(), 404); - } - return error(rqerror.message, rqerror.statusCode); - }); + }).catch(rqerror => error(rqerror.response.body.toString(), rqerror.statusCode)); } /**