Open platform to collect and prioritize feedback
enhancement: add more details to fetch error (#630)
Guilherme Oenning5dc4cd204c2a
diff --git a/public/services/actions/infra.ts b/public/services/actions/infra.tsindex 814363f05..7bc5cdeaf 100644--- a/public/services/actions/infra.ts+++ b/public/services/actions/infra.ts@@ -4,7 +4,8 @@ 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+ "vid_mate_check is not defined", // CSP error: thrown by VidMate, an Android Browser+ "SecurityError: Failed to read the 'cssRules' property from 'CSSStyleSheet': Cannot access rules" // CSP error: usually thrown because of bad Chrome Extensions];export const logError = async (message: string, err?: Error): Promise<Result | undefined> => {@@ -19,8 +20,10 @@ export const logError = async (message: string, err?: Error): Promise<Result | ustack: err ? err.stack : "<not available>"};- return http.post("/_api/log-error", { message, data }).then(response => {+ try {analytics.error(err);- return response;- });+ return await http.post("/_api/log-error", { message, data });+ } catch (err) {+ // tslint:disable-next-line:no-empty+ }};diff --git a/public/services/http.ts b/public/services/http.tsindex 82c4e60fc..a4b6bcb97 100644--- a/public/services/http.ts+++ b/public/services/http.ts@@ -34,13 +34,17 @@ async function toResult<T>(response: Response): Promise<Result<T>> {}async function request<T>(url: string, method: "GET" | "POST" | "PUT" | "DELETE", body?: any): Promise<Result<T>> {const headers = [["Accept", "application/json"], ["Content-Type", "application/json"]];- const response = await fetch(url, {- method,- headers,- body: JSON.stringify(body),- credentials: "same-origin"- });- return await toResult<T>(response);+ try {+ const response = await fetch(url, {+ method,+ headers,+ body: JSON.stringify(body),+ credentials: "same-origin"+ });+ return await toResult<T>(response);+ } catch (err) {+ throw new Error(`Failed to ${method} ${url} with body '${body ? JSON.stringify(body) : "<empty>"}'`);+ }}export const http = {