diff --git a/middlewares/send-error.js b/middlewares/send-error.js index 8afabe76236..43e70707a6c 100644 --- a/middlewares/send-error.js +++ b/middlewares/send-error.js @@ -19,7 +19,7 @@ module.exports = async (ctx, next) => { ctx.state.processMesId ); } - ctx.reply(e.toString()); + ctx.reply(e.toString(lang)); } else throw e; } }; diff --git a/middlewares/test-url.js b/middlewares/test-url.js index 7755a05145d..542416ae0c0 100644 --- a/middlewares/test-url.js +++ b/middlewares/test-url.js @@ -14,7 +14,7 @@ module.exports = async (ctx, next) => { await next(); } else { try { - const res = await got.get(url); + const res = await got(url); ctx.state.feedUrl = decodeURI(res.url); // handle redirect feed = await feedUtil.isFeedValid(res.body); if (!feed) { @@ -31,6 +31,7 @@ module.exports = async (ctx, next) => { feed = await parser.parseString(res.body); delete feed.items; ctx.state.feed = feed; + ctx.state.feedUrl = ctx.state.feedUrl[0]; await next(); // next break; default: diff --git a/utils/errors.js b/utils/errors.js index 3bd261a6f92..599f9c1c0f2 100644 --- a/utils/errors.js +++ b/utils/errors.js @@ -9,14 +9,14 @@ class ControllableError extends Error { } } - toString() { - return i18n[this.code]; + toString(lang) { + return i18n[lang][this.code]; } } exports.newCtrlErr = function(code, e) { const err = new ControllableError(e); - if (e.response) { + if (e && e.response) { switch (e.response.statusCode) { case 404: case 403: