Skip to content

Commit

Permalink
organize error constants
Browse files Browse the repository at this point in the history
  • Loading branch information
eshaham committed May 24, 2019
1 parent 3dbac70 commit 540369a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const LOGIN_RESULT = {
UNKNOWN_ERROR: 'UNKNOWN_ERROR',
};

export const NAVIGATION_ERRORS = {
export const ERRORS = {
TIMEOUT: 'TIMEOUT',
GENERIC: 'GENERIC',
};
Expand Down
5 changes: 0 additions & 5 deletions src/helpers/navigation.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import waitUntil from './waiting';

export const NAVIGATION_ERRORS = {
TIMEOUT: 'timeout',
GENERIC: 'generic',
};

export async function waitForNavigation(page, options) {
await page.waitForNavigation(options);
}
Expand Down
13 changes: 6 additions & 7 deletions src/scrapers/base-scraper.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { EventEmitter } from 'events';

import { SCRAPE_PROGRESS_TYPES, LOGIN_RESULT } from '../constants';
import { NAVIGATION_ERRORS } from '../helpers/navigation';
import { SCRAPE_PROGRESS_TYPES, LOGIN_RESULT, ERRORS } from '../constants';

const SCRAPE_PROGRESS = 'SCRAPE_PROGRESS';

Expand All @@ -14,11 +13,11 @@ function createErrorResult(errorType, errorMessage) {
}

function createTimeoutError(errorMessage) {
return createErrorResult(NAVIGATION_ERRORS.TIMEOUT, errorMessage);
return createErrorResult(ERRORS.TIMEOUT, errorMessage);
}

function createGenericNavigationError(errorMessage) {
return createErrorResult(NAVIGATION_ERRORS.GENERIC, errorMessage);
function createGenericError(errorMessage) {
return createErrorResult(ERRORS.GENERIC, errorMessage);
}

class BaseScraper {
Expand All @@ -41,7 +40,7 @@ class BaseScraper {
} catch (e) {
loginResult = e.timeout ?
createTimeoutError(e.message) :
createGenericNavigationError(e.message);
createGenericError(e.message);
}

let scrapeResult;
Expand All @@ -52,7 +51,7 @@ class BaseScraper {
scrapeResult =
e.timeout ?
createTimeoutError(e.message) :
createGenericNavigationError(e.message);
createGenericError(e.message);
}
} else {
scrapeResult = loginResult;
Expand Down

0 comments on commit 540369a

Please sign in to comment.