Skip to content

Commit

Permalink
fix(actions): cause handling for new rpc engine version
Browse files Browse the repository at this point in the history
  • Loading branch information
legobeat committed May 7, 2024
1 parent a3c76a3 commit 769dff6
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,9 @@ export default class UserStorageController extends BaseController<
state.isProfileSyncingEnabled = true;
});
} catch (e) {
const errorMessage = e instanceof Error
? ((e as any).data?.cause?.message || e.message)
: e;
const errorMessage =
// eslint-disable-next-line @typescript-eslint/no-explicit-any
e instanceof Error ? (e as any).data?.cause?.message || e.message : e;
throw new Error(
`${controllerName} - failed to enable profile syncing - ${errorMessage}`,
);
Expand Down
68 changes: 40 additions & 28 deletions ui/store/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export function tryUnlockMetamask(
dispatch(hideLoadingIndication());
})
.catch((err) => {
dispatch(unlockFailed(err.message));
dispatch(unlockFailed(err.data?.cause?.message || err.message));
dispatch(hideLoadingIndication());
return Promise.reject(err);
});
Expand Down Expand Up @@ -4171,7 +4171,7 @@ export function setConnectedStatusPopoverHasBeenShown(): ThunkAction<
return () => {
callBackgroundMethod('setConnectedStatusPopoverHasBeenShown', [], (err) => {
if (isErrorWithMessage(err)) {
throw new Error(err.message);
throw new Error(err.data?.cause?.message || err.message);
}
});
};
Expand All @@ -4181,7 +4181,7 @@ export function setRecoveryPhraseReminderHasBeenShown() {
return () => {
callBackgroundMethod('setRecoveryPhraseReminderHasBeenShown', [], (err) => {
if (isErrorWithMessage(err)) {
throw new Error(err.message);
throw new Error(err.data?.cause?.message || err.message);
}
});
};
Expand All @@ -4196,7 +4196,7 @@ export function setRecoveryPhraseReminderLastShown(
[lastShown],
(err) => {
if (isErrorWithMessage(err)) {
throw new Error(err.message);
throw new Error(err.data?.cause?.message || err.message);
}
},
);
Expand Down Expand Up @@ -4647,12 +4647,15 @@ export function fetchSmartTransactionFees(
return smartTransactionFees;
} catch (err) {
logErrorWithMessage(err);
if (isErrorWithMessage(err) && err.message.startsWith('Fetch error:')) {
const errorObj = parseSmartTransactionsError(err.message);
dispatch({
type: actionConstants.SET_SMART_TRANSACTIONS_ERROR,
payload: errorObj,
});
if (isErrorWithMessage(err)) {
const errorMessage = err.data?.cause?.message || err.message;
if (errorMessage.startsWith('Fetch error:')) {
const errorObj = parseSmartTransactionsError(errorMessage);
dispatch({
type: actionConstants.SET_SMART_TRANSACTIONS_ERROR,
payload: errorObj,
});
}
}
throw err;
}
Expand Down Expand Up @@ -4727,12 +4730,15 @@ export function signAndSendSmartTransaction({
return response.uuid;
} catch (err) {
logErrorWithMessage(err);
if (isErrorWithMessage(err) && err.message.startsWith('Fetch error:')) {
const errorObj = parseSmartTransactionsError(err.message);
dispatch({
type: actionConstants.SET_SMART_TRANSACTIONS_ERROR,
payload: errorObj,
});
if (isErrorWithMessage(err)) {
const errorMessage = err.data?.cause?.message || err.message;
if (errorMessage.startsWith('Fetch error:')) {
const errorObj = parseSmartTransactionsError(errorMessage);
dispatch({
type: actionConstants.SET_SMART_TRANSACTIONS_ERROR,
payload: errorObj,
});
}
}
throw err;
}
Expand All @@ -4753,12 +4759,15 @@ export function updateSmartTransaction(
]);
} catch (err) {
logErrorWithMessage(err);
if (isErrorWithMessage(err) && err.message.startsWith('Fetch error:')) {
const errorObj = parseSmartTransactionsError(err.message);
dispatch({
type: actionConstants.SET_SMART_TRANSACTIONS_ERROR,
payload: errorObj,
});
if (isErrorWithMessage(err)) {
const errorMessage = err.data?.cause?.message || err.message;
if (errorMessage.startsWith('Fetch error:')) {
const errorObj = parseSmartTransactionsError(errorMessage);
dispatch({
type: actionConstants.SET_SMART_TRANSACTIONS_ERROR,
payload: errorObj,
});
}
}
throw err;
}
Expand Down Expand Up @@ -4787,12 +4796,15 @@ export function cancelSmartTransaction(
await submitRequestToBackground('cancelSmartTransaction', [uuid]);
} catch (err) {
logErrorWithMessage(err);
if (isErrorWithMessage(err) && err.message.startsWith('Fetch error:')) {
const errorObj = parseSmartTransactionsError(err.message);
dispatch({
type: actionConstants.SET_SMART_TRANSACTIONS_ERROR,
payload: errorObj,
});
if (isErrorWithMessage(err)) {
const errorMessage = err.data?.cause?.message || err.message;
if (errorMessage.startsWith('Fetch error:')) {
const errorObj = parseSmartTransactionsError(errorMessage);
dispatch({
type: actionConstants.SET_SMART_TRANSACTIONS_ERROR,
payload: errorObj,
});
}
}
throw err;
}
Expand Down

0 comments on commit 769dff6

Please sign in to comment.