Skip to content

Commit

Permalink
refact: add traceble meta to getOrRefreshToken errors
Browse files Browse the repository at this point in the history
  • Loading branch information
kewitz committed Mar 1, 2024
1 parent 0bb7a93 commit 38c1b29
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions server/lib/transferwise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,12 @@ export async function getToken(connectedAccount: ConnectedAccount, refresh = fal
return diff > <number>connectedAccount.data.expires_in - 60 * 15;
};

const refreshAndUpdateToken = async connectedAccount => {
const refreshAndUpdateToken = async (connectedAccount: ConnectedAccount) => {
try {
const newToken = await getOrRefreshToken({ refreshToken: connectedAccount.refreshToken });
const newToken = await getOrRefreshToken({
refreshToken: connectedAccount.refreshToken,
errorMeta: { user: connectedAccount.CollectiveId, extra: { connectedAccountId: connectedAccount.id } },
});
if (!newToken) {
Activity.create({
type: ActivityTypes.CONNECTED_ACCOUNT_ERROR,
Expand Down Expand Up @@ -740,10 +743,12 @@ export const getOrRefreshToken = async ({
code,
refreshToken,
application,
errorMeta,
}: {
code?: string;
refreshToken?: string;
application?: boolean;
errorMeta?: Parameters<typeof reportErrorToSentry>[1];
}): Promise<AccessToken> => {
let data;
// Refresh Token
Expand Down Expand Up @@ -778,7 +783,7 @@ export const getOrRefreshToken = async ({
return token;
} catch (e) {
debug(JSON.stringify(e));
reportErrorToSentry(e, { feature: FEATURE.TRANSFERWISE });
reportErrorToSentry(e, { feature: FEATURE.TRANSFERWISE, ...errorMeta });
const error = parseError(e, "There was an error while refreshing host's Wise token");
throw error;
}
Expand Down

0 comments on commit 38c1b29

Please sign in to comment.