Skip to content

Commit

Permalink
add error logs to claim & add logging to console
Browse files Browse the repository at this point in the history
  • Loading branch information
Ridel1e committed Oct 13, 2023
1 parent f469ef4 commit f588f35
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/common/services/ErrorLogs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ export const captureOperationError = (
context?: object,
): void => {
const message = typeof error === 'string' ? error : error.message;

console.log('error: ', message);

Check warning on line 21 in src/common/services/ErrorLogs.ts

View workflow job for this annotation

GitHub Actions / Build Artifacts for Test

Unexpected console statement
console.log('network: ', network);

Check warning on line 22 in src/common/services/ErrorLogs.ts

View workflow job for this annotation

GitHub Actions / Build Artifacts for Test

Unexpected console statement
console.log('operation: ', operation);

Check warning on line 23 in src/common/services/ErrorLogs.ts

View workflow job for this annotation

GitHub Actions / Build Artifacts for Test

Unexpected console statement
console.log('candidate: ', candidate);

Check warning on line 24 in src/common/services/ErrorLogs.ts

View workflow job for this annotation

GitHub Actions / Build Artifacts for Test

Unexpected console statement
console.log('context: ', context);

Check warning on line 25 in src/common/services/ErrorLogs.ts

View workflow job for this annotation

GitHub Actions / Build Artifacts for Test

Unexpected console statement
Sentry.captureMessage(message, {
level: Severity.Critical,
extra: {
Expand Down
13 changes: 10 additions & 3 deletions src/network/cardano/api/rewards/claimRewards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
} from 'rxjs';

import { Currency } from '../../../../common/models/Currency';
import { captureOperationError } from '../../../../common/services/ErrorLogs';
import { TxId } from '../../../../common/types';
import { localStorageManager } from '../../../../common/utils/localStorageManager';
import { getAddresses } from '../../../../gateway/api/addresses';
Expand Down Expand Up @@ -57,6 +58,7 @@ interface ClaimTxResponse {
readonly transaction: Transaction | null;
readonly requiredAda: Currency;
readonly addresses: string[];
readonly error: Error | string | null;
}

export const buildClaimTx = (
Expand Down Expand Up @@ -164,12 +166,14 @@ export const buildClaimTx = (
}),
map((transaction) => ({
transaction,
error: null,
addresses: outputsData.map((item) => item.address),
requiredAda: new Currency(minAdaRequiredForClaiming, networkAsset),
})),
catchError(() =>
catchError((error) =>
of({
transaction: null,
error,
addresses: outputsData.map((item) => item.address),
requiredAda: new Currency(
minAdaRequiredForClaiming,
Expand Down Expand Up @@ -205,11 +209,14 @@ export const claimRewards = (rewardsData: RewardsData): Observable<TxId> => {
}

return buildClaimTx(rewardsData).pipe(
switchMap(({ transaction }) => {
switchMap(({ transaction, error }) => {
if (transaction) {
return submitTx(transaction);
}
throw new Error('Insufficient funds');
throw error;
}),
tap({
error: (error) => captureOperationError(error, 'cardano', 'claim'),
}),
tap(() =>
localStorageManager.set(
Expand Down

0 comments on commit f588f35

Please sign in to comment.