Skip to content

armgit / fider

Public Imported from GitHub
0

Open platform to collect and prioritize feedback

enhancement: better ui errors, catch unhandledrejection and ignore noisy errors (#622)

Guilherme Oenning43621ed96496
diff --git a/public/index.tsx b/public/index.tsx
index 2dea0033e..9e1d055ef 100644
--- a/public/index.tsx
+++ b/public/index.tsx
@@ -15,13 +15,21 @@ import "@fider/assets/styles/main.scss";
const logProductionError = (err: Error) => {
if (Fider.isProduction()) {
console.error(err); // tslint:disable-line
- actions.logError(err.message, err);
+ actions.logError(`react.ErrorBoundary: ${err.message}`, err);
}
};
+window.addEventListener("unhandledrejection", (evt: PromiseRejectionEvent) => {
+ if (evt.reason instanceof Error) {
+ actions.logError(`window.unhandledrejection: ${evt.reason.message}`, evt.reason);
+ } else if (evt.reason) {
+ actions.logError(`window.unhandledrejection: ${evt.reason.toString()}`);
+ }
+});
+
window.addEventListener("error", (evt: ErrorEvent) => {
if (evt.error && evt.colno > 0 && evt.lineno > 0) {
- actions.logError(evt.message, evt.error);
+ actions.logError(`window.error: ${evt.message}`, evt.error);
}
});
diff --git a/public/services/actions/infra.ts b/public/services/actions/infra.ts
index b0bae657c..814363f05 100644
--- a/public/services/actions/infra.ts
+++ b/public/services/actions/infra.ts
@@ -1,6 +1,19 @@
import { http, Result, navigator, analytics } from "@fider/services";
-export const logError = async (message: string, err?: Error): Promise<Result> => {
+const ignoreErrors = [
+ "http://gj.track.uc.cn/collect", // CSP error: UC Browser tries to use sendBeacon to this domain, which is blocked by our CSP rule
+ "null is not an object (evaluating 'c.sheet.insertRule')", // CSP error: UC Browser throws this error even when page is loaded sucessfully
+ "Refused to evaluate a string as JavaScript because 'unsafe-eval'", // CSP error: usually thrown because of bad Chrome Extensions
+ "vid_mate_check is not defined" // CSP error: thrown by VidMate, an Android Browser
+];
+
+export const logError = async (message: string, err?: Error): Promise<Result | undefined> => {
+ for (const pattern of ignoreErrors) {
+ if (message.indexOf(pattern) >= 0) {
+ return;
+ }
+ }
+
const data = {
url: navigator.url(),
stack: err ? err.stack : "<not available>"