From 8387a8ebd6910e86919e0fe0b346c9f80ad4c596 Mon Sep 17 00:00:00 2001 From: Maxim Baz Date: Sun, 24 Nov 2024 17:42:16 +0100 Subject: [PATCH] switch to rollbar on frontend --- app/api/report-error/route.ts | 7 ------- framer/Donation_Form.tsx | 14 ++------------ framer/Fundraiser.tsx | 14 ++------------ framer/Fundraiser_Admin.tsx | 17 +++++------------ framer/Renew_Payment.tsx | 14 ++------------ framer/Stats.tsx | 10 ++-------- framer/helpers-donation.ts | 12 +----------- framer/helpers-membership.ts | 12 +----------- framer/helpers.ts | 19 ++++++------------- 9 files changed, 21 insertions(+), 98 deletions(-) delete mode 100644 app/api/report-error/route.ts diff --git a/app/api/report-error/route.ts b/app/api/report-error/route.ts deleted file mode 100644 index e558b84..0000000 --- a/app/api/report-error/route.ts +++ /dev/null @@ -1,7 +0,0 @@ -export async function POST(req: Request) { - console.error( - "Users are experiencing critical problems on the page", - await req.text(), - ); - return Response.json({ message: "OK" }); -} diff --git a/framer/Donation_Form.tsx b/framer/Donation_Form.tsx index 73027ad..88868dd 100644 --- a/framer/Donation_Form.tsx +++ b/framer/Donation_Form.tsx @@ -496,18 +496,8 @@ export const withFundraiser = (Component: any): ComponentType => { }); }; - request().catch(async (err: Error) => { - console.error(err?.toString()); - - try { - await notifyAboutClientSideError( - store.env, - "donation withFundraiser", - err?.toString(), - ); - } catch (e) { - console.error(e); - } + request().catch((err: Error) => { + notifyAboutClientSideError("donation withFundraiser", err?.toString()); }); }, []); diff --git a/framer/Fundraiser.tsx b/framer/Fundraiser.tsx index e54998c..fec042c 100644 --- a/framer/Fundraiser.tsx +++ b/framer/Fundraiser.tsx @@ -40,19 +40,9 @@ export const loadData = (Component: any): ComponentType => { }); }; - request().catch(async (err: Error) => { - console.error(err?.toString()); + request().catch((err: Error) => { setStore({ data: null, hasError: true, isLoading: false }); - - try { - await notifyAboutClientSideError( - "prod", - "fundraiser loadData", - err?.toString(), - ); - } catch (e) { - console.error(e); - } + notifyAboutClientSideError("fundraiser loadData", err?.toString()); }); }, []); diff --git a/framer/Fundraiser_Admin.tsx b/framer/Fundraiser_Admin.tsx index 0cd51c6..234de3e 100644 --- a/framer/Fundraiser_Admin.tsx +++ b/framer/Fundraiser_Admin.tsx @@ -46,19 +46,12 @@ export const loadData = (Component: any): ComponentType => { }); }; - request().catch(async (err: Error) => { - console.error(err?.toString()); + request().catch((err: Error) => { setStore({ data: null, hasError: true, isLoading: false }); - - try { - await notifyAboutClientSideError( - "prod", - "fundraiser-admin loadData", - err?.toString(), - ); - } catch (e) { - console.error(e); - } + notifyAboutClientSideError( + "fundraiser-admin loadData", + err?.toString(), + ); }); }, []); diff --git a/framer/Renew_Payment.tsx b/framer/Renew_Payment.tsx index a723500..e42819e 100644 --- a/framer/Renew_Payment.tsx +++ b/framer/Renew_Payment.tsx @@ -36,19 +36,9 @@ export const loadUrl = (Component: any): ComponentType => { setStore({ url: body.url, hasError: false }); }; - request().catch(async (err: Error) => { - console.error(err?.toString()); + request().catch((err: Error) => { setStore({ url: null, hasError: true }); - - try { - await notifyAboutClientSideError( - "prod", - "renew-payment loadUrl", - err?.toString(), - ); - } catch (e) { - console.error(e); - } + notifyAboutClientSideError("renew-payment loadUrl", err?.toString()); }); }, []); diff --git a/framer/Stats.tsx b/framer/Stats.tsx index 3de1adf..c54a870 100644 --- a/framer/Stats.tsx +++ b/framer/Stats.tsx @@ -40,14 +40,8 @@ export const loadKpi = (Component: any): ComponentType => { }); }; - request().catch(async (err: Error) => { - console.error(err?.toString()); - - try { - await notifyAboutClientSideError("prod", "loadKpi", err?.toString()); - } catch (e) { - console.error(e); - } + request().catch((err: Error) => { + notifyAboutClientSideError("loadKpi", err?.toString()); }); }, []); diff --git a/framer/helpers-donation.ts b/framer/helpers-donation.ts index 73d45e5..bafae83 100644 --- a/framer/helpers-donation.ts +++ b/framer/helpers-donation.ts @@ -148,17 +148,7 @@ const submitDonation = async (store: any, setStore: any) => { } } catch (err) { alert(errorMessage); - console.error(err?.toString()); - - try { - await notifyAboutClientSideError( - store.env, - "submitDonation", - err?.toString(), - ); - } catch (e) { - console.error(e); - } + notifyAboutClientSideError("submitDonation", err?.toString()); } setStore({ isLoading: false }); diff --git a/framer/helpers-membership.ts b/framer/helpers-membership.ts index 96d0aa9..5ca1f98 100644 --- a/framer/helpers-membership.ts +++ b/framer/helpers-membership.ts @@ -79,17 +79,7 @@ const submitMembership = async (store: any, setStore: any) => { } } catch (err) { alert(errorMessage); - console.error(err?.toString()); - - try { - await notifyAboutClientSideError( - store.env, - "submitMembership", - err?.toString(), - ); - } catch (e) { - console.error(e); - } + notifyAboutClientSideError("submitMembership", err?.toString()); } setStore({ isLoading: false }); diff --git a/framer/helpers.ts b/framer/helpers.ts index 3c39f97..52531d1 100644 --- a/framer/helpers.ts +++ b/framer/helpers.ts @@ -42,23 +42,16 @@ const submitForm = async ( return await response.json(); }; -const notifyAboutClientSideError = async ( - env: string, - action: string, - error?: string, -) => { +const notifyAboutClientSideError = (action: string, error?: string) => { + console.error(`Client-side error in ${action}: ${error}`); if (error?.includes("NetworkError")) { return; } - const response = await fetch(apiUrl(env, "report-error"), { - method: "POST", - headers: { "Content-type": "application/json;charset=UTF-8" }, - body: JSON.stringify({ action, error }), - }); - - if (!response.ok) { - throw new Error("Unable to submit report about the critical error"); + // @ts-ignore + if (typeof Rollbar !== "undefined") { + // @ts-ignore + Rollbar.error(`Client-side error in ${action}: ${error}`); } };