Skip to content

Commit

Permalink
implement logging for translation failure
Browse files Browse the repository at this point in the history
  • Loading branch information
p7g authored and macdja38 committed Jul 14, 2018
1 parent c600a36 commit 47c0e00
Show file tree
Hide file tree
Showing 3 changed files with 493 additions and 1,195 deletions.
36 changes: 35 additions & 1 deletion PvPCraft.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class PvPCraft {
// this.rejectReadyPromise = reject;
});

this.captureMissingTranslation = this.captureMissingTranslation.bind(this);
this.getChannelLanguage = this.getChannelLanguage.bind(this);
this.translate = (channelID, guildID) =>
this.i10010n(this.getChannelLanguage(channelID, guildID));
Expand Down Expand Up @@ -255,7 +256,7 @@ class PvPCraft {
readyI10010n() {
this.i10010n = i10010n.init({
db: require("./config/translations.db"),
logger: () => {},
logger: this.captureMissingTranslation,
addTemplateData: () => {},
});
}
Expand Down Expand Up @@ -547,6 +548,39 @@ class PvPCraft {
})
}

captureMissingTranslation(errorType, data, message) {
const errTypes = i10010n.ErrorTypes;
let level;

switch (errorType) {
case errTypes.MISSING_TEMPLATE_DATA:
level = "warning";
break;
case errTypes.MISSING_LOCALE_DATA:
level = "info";
break;
case errTypes.USER_FUNCTION_FAILED:
case errTypes.MISSING_DB:
case errTypes.MISSING_LOCALE:
default:
level = "error";
break;
}

this.raven.captureMessage(
errorType,
{
level,
tags: {
locale: data.locale,
user_function: data.user_function,
template: (data.template || []).join(",").replace(/\s/g, "-"),
},
extra: Object.assign({ message }, data)
}
);
}

shutDown() {
setTimeout(() => {
process.exit(1)
Expand Down
Loading

0 comments on commit 47c0e00

Please sign in to comment.