Refactoring task errors

This commit is contained in:
2020-05-17 12:25:34 +03:00
parent 91684d0bad
commit 950345ffdb
5 changed files with 38 additions and 32 deletions

View File

@ -1,15 +1,13 @@
import { ActionController, registerAction } from './ActionController';
import { AbortTaskError } from '../Errors';
import { AbortTaskError, taskError } from '../Errors';
import { Args } from '../Queue/Args';
import { Task } from '../Queue/TaskProvider';
@registerAction
export class ClickButtonAction extends ActionController {
async run(args: Args, task: Task): Promise<any> {
if (!args.selector) {
throw new AbortTaskError('No selector');
}
const el = jQuery(args.selector);
const selector = args.selector || taskError('No selector');
const el = jQuery(selector);
if (el.length === 1) {
console.log('CLICK BUTTON', el);
el.trigger('click');

View File

@ -1,14 +1,12 @@
import { ActionController, registerAction } from './ActionController';
import { AbortTaskError } from '../Errors';
import { taskError } from '../Errors';
import { Args } from '../Queue/Args';
import { Task } from '../Queue/TaskProvider';
@registerAction
export class GoToPageAction extends ActionController {
async run(args: Args, task: Task): Promise<any> {
if (!args.path) {
throw new AbortTaskError('No path');
}
window.location.assign(args.path);
const path = args.path || taskError('Empty path');
window.location.assign(path);
}
}

View File

@ -1,5 +1,5 @@
import { ActionController, registerAction } from './ActionController';
import { AbortTaskError, ActionError, TryLaterError } from '../Errors';
import { AbortTaskError, ActionError, taskError, TryLaterError } from '../Errors';
import { grabResourceDeposits } from '../Page/SlotBlock';
import { UpgradeBuildingTask } from '../Task/UpgradeBuildingTask';
import { ResourceDeposit } from '../Game';
@ -15,10 +15,7 @@ export class UpgradeResourceToLevel extends ActionController {
throw new ActionError('No deposits');
}
const villageId = args.villageId;
if (villageId === undefined) {
throw new AbortTaskError('No village id');
}
const villageId = args.villageId || taskError('No village id');
const requiredLevel = getNumber(args.level);