mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: detect theme errors and catch them (#7589)
* FEATURE: detect theme errors and catch them * Bump COMPILER_VERSION * Feedback * Override eslint no console for one line * Can't use our ajax method * remove emoji from translation file
This commit is contained in:
@@ -660,5 +660,39 @@ export function postRNWebviewMessage(prop, value) {
|
||||
}
|
||||
}
|
||||
|
||||
function reportToLogster(name, error) {
|
||||
const data = {
|
||||
message: `${name} theme/component is throwing errors`,
|
||||
stacktrace: error.stack
|
||||
};
|
||||
|
||||
Ember.$.ajax(`${Discourse.BaseUri}/logs/report_js_error`, {
|
||||
data,
|
||||
type: "POST",
|
||||
cache: false
|
||||
});
|
||||
}
|
||||
// this function is used in lib/theme_javascript_compiler.rb
|
||||
export function rescueThemeError(name, error, api) {
|
||||
/* eslint-disable-next-line no-console */
|
||||
console.error(`"${name}" error:`, error);
|
||||
reportToLogster(name, error);
|
||||
|
||||
const currentUser = api.getCurrentUser();
|
||||
if (!currentUser || !currentUser.admin) {
|
||||
return;
|
||||
}
|
||||
|
||||
const path = `${Discourse.BaseUri}/admin/customize/themes`;
|
||||
const message = I18n.t("themes.broken_theme_alert", {
|
||||
theme: name,
|
||||
path: `<a href="${path}">${path}</a>`
|
||||
});
|
||||
const alertDiv = document.createElement("div");
|
||||
alertDiv.classList.add("broken-theme-alert");
|
||||
alertDiv.innerHTML = `⚠️ ${message}`;
|
||||
document.body.prepend(alertDiv);
|
||||
}
|
||||
|
||||
// This prevents a mini racer crash
|
||||
export default {};
|
||||
|
||||
Reference in New Issue
Block a user