Skip to content

Commit

Permalink
Fix: Scraping error message now appears in account log
Browse files Browse the repository at this point in the history
  • Loading branch information
brafdlog committed Oct 29, 2022
1 parent 70c2181 commit 0f21212
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/backend/import/importTransactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,22 @@ import _ from 'lodash';
import moment from 'moment';
import { configFilePath, userDataPath } from '@/app-globals';
import {
AccountToScrapeConfig, Config, EnrichedTransaction, FinancialAccountDetails,
AccountToScrapeConfig,
Config,
EnrichedTransaction,
FinancialAccountDetails,
ScaperScrapingResult
} from '@/backend/commonTypes';
import { getConfig } from '@/backend/configManager/configManager';
import * as bankScraper from '@/backend/import/bankScraper';
import * as categoryCalculation from '@/backend/import/categoryCalculationScript';
import {
AccountStatus, BudgetTrackingEventEmitter, DownalodChromeEvent, EventNames, EventPublisher, ImporterEvent
AccountStatus,
BudgetTrackingEventEmitter,
DownalodChromeEvent,
EventNames,
EventPublisher,
ImporterEvent
} from '../eventEmitters/EventEmitter';
import { calculateTransactionHash } from '../transactions/transactions';
import getChrome from './downloadChromium';
Expand Down Expand Up @@ -97,15 +105,15 @@ async function fetchTransactions(
const emitImporterProgressEvent = async (eventCompanyId: string, message: string) => {
await eventPublisher.emit(EventNames.IMPORTER_PROGRESS, buildImporterEvent(account, { message }));
};

const companyId = account.key;
const scrapeResult = await bankScraper.scrape({
companyId: account.key,
companyId,
credentials: account.loginFields,
startDate,
showBrowser,
}, emitImporterProgressEvent, chromePath);
if (!scrapeResult.success) {
throw new Error(scrapeResult.errorMessage || scrapeResult.errorType);
throw new Error(`${scrapeResult.errorType}: ${scrapeResult.errorMessage}`);
}

const transactions = await postProcessTransactions(account, scrapeResult);
Expand All @@ -114,7 +122,7 @@ async function fetchTransactions(
return transactions;
} catch (error) {
await eventPublisher.emit(EventNames.IMPORTER_ERROR, buildImporterEvent(account, {
message: 'Importer error', error, status: AccountStatus.ERROR
message: error.message, error, status: AccountStatus.ERROR
}));
throw error;
}
Expand Down

0 comments on commit 0f21212

Please sign in to comment.