Skip to content

Commit

Permalink
feat: add error id on user notification (#88)
Browse files Browse the repository at this point in the history
* fix: sentry error message on import

* feat: prettier

* feat: add error id on user notification
  • Loading branch information
0xbulma authored Sep 18, 2023
1 parent 63d77fe commit 9ee038b
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"tabWidth": 2,
"printWidth": 100
"printWidth": 80
}
7 changes: 5 additions & 2 deletions src/pages/Modals/ConnectVaultModal/components/A2_SignStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,13 @@ export default function SignStep({
}
}
} catch (e) {
Sentry.captureException(e);
const eventId = Sentry.captureException(e);
console.error(e);
notificationAdded({
text: "En error occurred, please clean your cache and refresh your page.",
text:
"En error occurred, please clean your cache and refresh your page." +
" - Error id: " +
eventId,
type: "error",
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,12 @@ export default function AccessRecoveryKey({ onConnected }: Props): JSX.Element {
setNoVaultFound(true);
}
} catch (e) {
Sentry.captureException(e);
const eventId = Sentry.captureException(e);
notificationAdded({
text: "En error occurred, please clean your cache and refresh your page.",
text:
"En error occurred, please clean your cache and refresh your page." +
" - Error id: " +
eventId,
type: "error",
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,15 +206,19 @@ export default function CreateVaultStep({
await create(ownershipSignature, seed, identifier);
onCreated();
} catch (e) {
let eventId: string;
Sentry.withScope(function (scope) {
scope.setLevel("fatal");
Sentry.captureException(e);
eventId = Sentry.captureException(e);
});
console.error(e);
setStatus("idle");
notificationAdded({
type: "error",
text: "An error occurred, while importing new owner",
text:
"An error occurred, while importing new owner" +
" - Error id: " +
eventId,
});
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,13 @@ export default function VaultDetectedStep({
throw new Error();
}
} catch (e) {
Sentry.captureException(e);
const eventId = Sentry.captureException(e);
console.error(e);
notificationAdded({
text: "En error occurred, please clean your cache and refresh your page.",
text:
"En error occurred, please clean your cache and refresh your page." +
" - Error id: " +
eventId,
type: "error",
});
}
Expand Down
8 changes: 6 additions & 2 deletions src/pages/Modals/GenerateRecoveryKey/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,17 @@ export default function GenerateRecoveryKeyModal(): JSX.Element {
setKey(_key);
setName(_name);
} catch (e) {
let eventId: string;
Sentry.withScope(function (scope) {
scope.setLevel("fatal");
Sentry.captureException(e);
eventId = Sentry.captureException(e);
});
console.log("e", e);
notificationAdded({
text: "An error occurred while saving your vault, please try again.",
text:
"An error occurred while saving your vault, please try again." +
" - Error id: " +
eventId,
type: "error",
});
} finally {
Expand Down
55 changes: 40 additions & 15 deletions src/pages/Modals/ImportAccount/provider/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,19 @@ export default function ImportAccountModalProvider({
setAccountTypes(null);
};

const triggerError = (e) => {
const triggerError = (e: Error) => {
let eventId: string;
Sentry.withScope(function (scope) {
scope.setLevel("fatal");
Sentry.captureException(e?.response?.data);
eventId = Sentry.captureException(e);
});
console.error(e);
const text = e?.message
? e.message
: "An error occurred while saving your vault, please try again.";

notificationAdded({
text: "An error occurred while saving your vault, please try again.",
text: text + " - Error id: " + eventId,
type: "error",
});
setImporting(null);
Expand Down Expand Up @@ -124,7 +129,7 @@ export default function ImportAccountModalProvider({

if (_importType === "owner") {
if (alreadyOwner) {
triggerError("Already imported as Owner");
triggerError(new Error("Account already imported as Owner"));
return;
}
await vault.addOwner({
Expand Down Expand Up @@ -157,13 +162,17 @@ export default function ImportAccountModalProvider({
commitmentReceipt = _commitmentReceipt;
commitmentMapperPubKey = _commitmentMapperPubKey;
} catch (e) {
let eventId: string;
Sentry.withScope(function (scope) {
scope.setLevel("fatal");
Sentry.captureException(e?.response?.data);
eventId = Sentry.captureException(e);
});
console.error(e);
notificationAdded({
text: "Account already imported into another vault.",
text:
"Account already imported into another vault." +
" - Error id: " +
eventId,
type: "error",
});
setImporting(null);
Expand All @@ -173,7 +182,7 @@ export default function ImportAccountModalProvider({

if (_importType === "account") {
if (alreadyImported) {
triggerError("Already imported");
triggerError(new Error("Account already imported"));
return;
}
await vault.importAccount({
Expand Down Expand Up @@ -241,12 +250,16 @@ export default function ImportAccountModalProvider({
e?.response?.data?.error === "Address is already used for a commitment!"
) {
console.error(e);
let eventId: string;
Sentry.withScope(function (scope) {
scope.setLevel("fatal");
Sentry.captureException(e?.response?.data);
eventId = Sentry.captureException(e);
});
notificationAdded({
text: "Telegram account already imported in this vault or in another one",
text:
"Telegram account already imported in this vault or in another one" +
" - Error id: " +
eventId,
type: "error",
});
setImporting(null);
Expand Down Expand Up @@ -302,12 +315,16 @@ export default function ImportAccountModalProvider({
e?.response?.data?.error === "Address is already used for a commitment!"
) {
console.error(e);
let eventId: string;
Sentry.withScope(function (scope) {
scope.setLevel("fatal");
Sentry.captureException(e?.response?.data);
eventId = Sentry.captureException(e);
});
notificationAdded({
text: "Github account already imported in this vault or in another one",
text:
"Github account already imported in this vault or in another one" +
" - Error id: " +
eventId,
type: "error",
});
setImporting(null);
Expand Down Expand Up @@ -365,12 +382,16 @@ export default function ImportAccountModalProvider({
e?.response?.data?.error === "Address is already used for a commitment!"
) {
console.error(e);
let eventId: string;
Sentry.withScope(function (scope) {
scope.setLevel("fatal");
Sentry.captureException(e?.response?.data);
eventId = Sentry.captureException(e);
});
notificationAdded({
text: "Twitter account already imported in this vault or in another one",
text:
"Twitter account already imported in this vault or in another one" +
" - Error id: " +
eventId,
type: "error",
});
setImporting(null);
Expand Down Expand Up @@ -427,12 +448,16 @@ export default function ImportAccountModalProvider({
e?.response?.data?.error === "Address is already used for a commitment!"
) {
console.error(e);
let eventId: string;
Sentry.withScope(function (scope) {
scope.setLevel("fatal");
Sentry.captureException(e?.response?.data);
eventId = Sentry.captureException(e);
});
notificationAdded({
text: "Twitter account already imported in this vault or in another one",
text:
"Twitter account already imported in this vault or in another one" +
" - Error id: " +
eventId,
type: "error",
});
setImporting(null);
Expand Down
7 changes: 5 additions & 2 deletions src/pages/Modals/MyVault/Settings/components/Customize.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,17 @@ export default function Customize() {
setEditIsOpen(false);
} catch (e) {
console.error("Update name", e);
Sentry.captureException(e, {
const eventId = Sentry.captureException(e, {
tags: {
file: "Customization.tsx",
function: "saveNewName",
},
});
notificationAdded({
text: "An error occurred while saving your vault, please try again.",
text:
"An error occurred while saving your vault, please try again." +
" - Error id: " +
eventId,
type: "error",
});
} finally {
Expand Down
7 changes: 5 additions & 2 deletions src/pages/Modals/MyVault/Settings/components/Security.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,12 @@ export default function Security() {
try {
await vault.setKeepConnected(vault.connectedOwner, !vault.keepConnected);
} catch (e) {
Sentry.captureException(e);
const eventId = Sentry.captureException(e);
notificationAdded({
text: "An error occurred while saving your vault, please try again.",
text:
"An error occurred while saving your vault, please try again." +
" - Error id: " +
eventId,
type: "error",
});
} finally {
Expand Down

0 comments on commit 9ee038b

Please sign in to comment.