Skip to content

Commit 408e6ba

Browse files
committed
🥅 server: name and fingerprint warning-level exceptions
1 parent 7d9b226 commit 408e6ba

6 files changed

Lines changed: 80 additions & 28 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@exactly/server": patch
3+
---
4+
5+
🥅 name and fingerprint warning-level exceptions

‎server/api/card.ts‎

Lines changed: 49 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { captureException, setContext, setUser } from "@sentry/node";
1+
import { captureException, setContext, setUser, withScope } from "@sentry/node";
22
import { Mutex } from "async-mutex";
33
import { eq, inArray, ne } from "drizzle-orm";
44
import { Hono } from "hono";
@@ -221,16 +221,23 @@ function decrypt(base64Secret: string, base64Iv: string, secretKey: string): str
221221
if (!issue) throw error;
222222
const shouldCapture = issue.type === "NotFoundError" || status === "ACTIVE";
223223
if (shouldCapture) {
224-
captureException(issue.error, {
225-
level: "warning",
226-
extra: {
227-
cardId: id,
228-
credentialId,
229-
pandaId: credential.pandaId,
230-
status,
231-
shouldCapture,
232-
userIssue: issue.type,
233-
},
224+
withScope((scope) => {
225+
scope.addEventProcessor((event) => {
226+
if (event.exception?.values?.[0]) event.exception.values[0].type = issue.type;
227+
return event;
228+
});
229+
captureException(issue.error, {
230+
level: "warning",
231+
fingerprint: ["{{ default }}", issue.type],
232+
extra: {
233+
cardId: id,
234+
credentialId,
235+
pandaId: credential.pandaId,
236+
status,
237+
shouldCapture,
238+
userIssue: issue.type,
239+
},
240+
});
234241
});
235242
}
236243
return null;
@@ -386,15 +393,22 @@ function decrypt(base64Secret: string, base64Iv: string, secretKey: string): str
386393
const hasCardHistory = credential.cards.length > 0;
387394
const shouldCapture = issue.type === "NotFoundError" || hasCardHistory;
388395
if (shouldCapture) {
389-
captureException(issue.error, {
390-
level: "warning",
391-
extra: {
392-
credentialId,
393-
hasCardHistory,
394-
pandaId: credential.pandaId,
395-
statuses: credential.cards.map(({ status }) => status),
396-
userIssue: issue.type,
397-
},
396+
withScope((scope) => {
397+
scope.addEventProcessor((event) => {
398+
if (event.exception?.values?.[0]) event.exception.values[0].type = issue.type;
399+
return event;
400+
});
401+
captureException(issue.error, {
402+
level: "warning",
403+
fingerprint: ["{{ default }}", issue.type],
404+
extra: {
405+
credentialId,
406+
hasCardHistory,
407+
pandaId: credential.pandaId,
408+
statuses: credential.cards.map(({ status }) => status),
409+
userIssue: issue.type,
410+
},
411+
});
398412
});
399413
}
400414
return c.json({ code: "no panda" }, 403);
@@ -588,8 +602,22 @@ function handlePlatinumUpgrade(credentialId: string, account: InferOutput<typeof
588602
})
589603
.catch((error: unknown) => {
590604
const isPaxConfigError = error instanceof Error && error.message.includes("missing pax");
605+
if (isPaxConfigError) {
606+
withScope((scope) => {
607+
scope.addEventProcessor((event) => {
608+
if (event.exception?.values?.[0]) event.exception.values[0].type = "missing pax";
609+
return event;
610+
});
611+
captureException(error, {
612+
level: "warning",
613+
fingerprint: ["{{ default }}", "missing pax"],
614+
extra: { credentialId, account, productId: SIGNATURE_PRODUCT_ID, scope: "basic", isPaxConfigError },
615+
});
616+
});
617+
return;
618+
}
591619
captureException(error, {
592-
level: isPaxConfigError ? "warning" : "error",
620+
level: "error",
593621
extra: { credentialId, account, productId: SIGNATURE_PRODUCT_ID, scope: "basic", isPaxConfigError },
594622
});
595623
});

‎server/hooks/activity.ts‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,15 @@ export default new Hono().post(
199199
for (const result of results) {
200200
if (result.status === "fulfilled") continue;
201201
if (result.reason instanceof Error && result.reason.message === "NoBalance()") {
202-
captureException(result.reason, {
203-
level: "warning",
204-
fingerprint: ["{{ default }}", result.reason.message],
202+
withScope((captureScope) => {
203+
captureScope.addEventProcessor((event) => {
204+
if (event.exception?.values?.[0]) event.exception.values[0].type = "NoBalance";
205+
return event;
206+
});
207+
captureException(result.reason, {
208+
level: "warning",
209+
fingerprint: ["{{ default }}", "NoBalance"],
210+
});
205211
});
206212
continue;
207213
}

‎server/hooks/panda.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,13 @@ export default new Hono().post(
403403
) !== amount
404404
) {
405405
debug(`${payload.action}:${payload.body.spend.status}`, payload.body.id, "bad collection");
406-
captureException(new Error("bad collection"), { level: "warning", contexts: { tx: { call, trace } } });
406+
const issue = new Error("bad collection");
407+
issue.name = "bad collection";
408+
captureException(issue, {
409+
level: "warning",
410+
fingerprint: ["{{ default }}", issue.message],
411+
contexts: { tx: { call, trace } },
412+
});
407413
throw new PandaError("bad collection", 551 as UnofficialStatusCode);
408414
}
409415
return authorize();

‎server/test/hooks/activity.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ function isNoBalance(error: unknown, hint: unknown, level: "error" | "warning")
635635
error.message === "NoBalance()" &&
636636
data?.level === level &&
637637
Array.isArray(data.fingerprint) &&
638-
data.fingerprint.join(":") === "{{ default }}:NoBalance()"
638+
data.fingerprint.join(":") === "{{ default }}:NoBalance"
639639
);
640640
}
641641

‎server/utils/ramps/manteca.ts‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ export async function uploadIdentityFile(
6464
delay: 1000,
6565
retryCount: 2,
6666
shouldRetry: ({ error }) => {
67-
captureException(error, { level: "warning" });
67+
const title = "upload identity file";
68+
captureException(error, { level: "warning", fingerprint: ["{{ default }}", title] });
6869
return true;
6970
},
7071
},
@@ -260,7 +261,13 @@ export async function getProvider(
260261
(task) => task.required && task.status === "PENDING",
261262
);
262263
if (hasPendingTasks) {
263-
captureException(new Error("has pending tasks"), { level: "warning", contexts: { mantecaUser } });
264+
const issue = new Error("has pending tasks");
265+
issue.name = "has pending tasks";
266+
captureException(issue, {
267+
level: "warning",
268+
fingerprint: ["{{ default }}", issue.message],
269+
contexts: { mantecaUser },
270+
});
264271
return { onramp: { currencies, cryptoCurrencies: [] }, status: "NOT_STARTED" };
265272
}
266273
return { onramp: { currencies, cryptoCurrencies: [] }, status: "ONBOARDING" };

0 commit comments

Comments
 (0)