Skip to content

Commit

Permalink
fix(error-handling): 🐛first feedUrl from array and fix lang when set …
Browse files Browse the repository at this point in the history
…handeing
  • Loading branch information
fengkx committed Jun 15, 2019
1 parent c1a9567 commit ed45a20
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion middlewares/send-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = async (ctx, next) => {
ctx.state.processMesId
);
}
ctx.reply(e.toString());
ctx.reply(e.toString(lang));
} else throw e;
}
};
3 changes: 2 additions & 1 deletion middlewares/test-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions utils/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit ed45a20

Please sign in to comment.