From dad586120b646c0c7fe277e87ab905f8e59e4807 Mon Sep 17 00:00:00 2001 From: bloodyowl Date: Wed, 12 Jun 2024 11:46:46 +0200 Subject: [PATCH] Forward errors to logs --- clients/banking/src/utils/gql.ts | 10 ++++++++++ clients/onboarding/src/utils/gql.ts | 10 ++++++++++ clients/payment/src/utils/gql.ts | 10 ++++++++++ server/src/app.ts | 19 +++++++++++++++++++ 4 files changed, 49 insertions(+) diff --git a/clients/banking/src/utils/gql.ts b/clients/banking/src/utils/gql.ts index f45fbb171..a7f790cda 100644 --- a/clients/banking/src/utils/gql.ts +++ b/clients/banking/src/utils/gql.ts @@ -106,6 +106,16 @@ const makeRequest: MakeRequest = ({ url, headers, operationName, document, varia .flatMapError(error => filterOutUnauthorizedError(operationName, error)) .tapError(errors => { ClientError.forEach(errors, error => { + try { + navigator.sendBeacon( + "/api/errors/report", + JSON.stringify({ + clientRequestId: requestId, + clientErrorName: error.name, + clientErrorMessage: error.message, + }), + ); + } catch (err) {} errorToRequestId.set(error, requestId); }); }); diff --git a/clients/onboarding/src/utils/gql.ts b/clients/onboarding/src/utils/gql.ts index 7cde2beb9..b4957a252 100644 --- a/clients/onboarding/src/utils/gql.ts +++ b/clients/onboarding/src/utils/gql.ts @@ -72,6 +72,16 @@ export const client = new Client({ ) .tapError(errors => { ClientError.forEach(errors, error => { + try { + navigator.sendBeacon( + "/api/errors/report", + JSON.stringify({ + clientRequestId: requestId, + clientErrorName: error.name, + clientErrorMessage: error.message, + }), + ); + } catch (err) {} errorToRequestId.set(error, requestId); }); }); diff --git a/clients/payment/src/utils/gql.ts b/clients/payment/src/utils/gql.ts index 43951f939..b082c1f25 100644 --- a/clients/payment/src/utils/gql.ts +++ b/clients/payment/src/utils/gql.ts @@ -72,6 +72,16 @@ export const client = new Client({ ) .tapError(errors => { ClientError.forEach(errors, error => { + try { + navigator.sendBeacon( + "/api/errors/report", + JSON.stringify({ + clientRequestId: requestId, + clientErrorName: error.name, + clientErrorMessage: error.message, + }), + ); + } catch (err) {} errorToRequestId.set(error, requestId); }); }); diff --git a/server/src/app.ts b/server/src/app.ts index f9167199a..3740c4cec 100644 --- a/server/src/app.ts +++ b/server/src/app.ts @@ -775,6 +775,25 @@ export const start = async ({ } }); + /** + * Log request issue to mezmo + */ + app.post("/api/errors/report", async (request, reply) => { + const success = Option.fromNullable(request.body) + .flatMap(body => (typeof body === "string" ? Option.Some(body) : Option.None())) + .toResult("Invalid body") + .flatMap(body => Result.fromExecution(() => JSON.parse(body) as unknown)) + .tapOk(body => { + request.log.warn({ + name: "ClientSideError", + contents: body, + }); + }) + .isOk(); + + return reply.send({ success }); + }); + /** * Exposes environement variables to the client apps at runtime. * The client simply has to load ``