Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forward errors to logs #759

Merged
merged 1 commit into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions clients/banking/src/utils/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
Expand Down
10 changes: 10 additions & 0 deletions clients/onboarding/src/utils/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
Expand Down
10 changes: 10 additions & 0 deletions clients/payment/src/utils/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
Expand Down
19 changes: 19 additions & 0 deletions server/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<script src="/env.js"></script>`
Expand Down
Loading