Refactoring task errors
This commit is contained in:
parent
91684d0bad
commit
950345ffdb
@ -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');
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
|
@ -1,10 +1,3 @@
|
||||
export class GrabError extends Error {
|
||||
constructor(msg: string = '') {
|
||||
super(msg);
|
||||
Object.setPrototypeOf(this, GrabError.prototype);
|
||||
}
|
||||
}
|
||||
|
||||
export class VillageNotFound extends Error {
|
||||
constructor(msg: string = '') {
|
||||
super(msg);
|
||||
@ -12,6 +5,23 @@ export class VillageNotFound extends Error {
|
||||
}
|
||||
}
|
||||
|
||||
export class TryLaterError extends Error {
|
||||
readonly seconds: number;
|
||||
|
||||
constructor(seconds: number, msg: string = '') {
|
||||
super(msg);
|
||||
this.seconds = seconds;
|
||||
Object.setPrototypeOf(this, TryLaterError.prototype);
|
||||
}
|
||||
}
|
||||
|
||||
export class GrabError extends Error {
|
||||
constructor(msg: string = '') {
|
||||
super(msg);
|
||||
Object.setPrototypeOf(this, GrabError.prototype);
|
||||
}
|
||||
}
|
||||
|
||||
export class ActionError extends Error {
|
||||
constructor(msg: string = '') {
|
||||
super(msg);
|
||||
@ -26,16 +36,13 @@ export class AbortTaskError extends Error {
|
||||
}
|
||||
}
|
||||
|
||||
export class TryLaterError extends Error {
|
||||
readonly seconds: number;
|
||||
|
||||
constructor(seconds: number, msg: string = '') {
|
||||
export class FailTaskError extends Error {
|
||||
constructor(msg: string = '') {
|
||||
super(msg);
|
||||
this.seconds = seconds;
|
||||
Object.setPrototypeOf(this, TryLaterError.prototype);
|
||||
Object.setPrototypeOf(this, FailTaskError.prototype);
|
||||
}
|
||||
}
|
||||
|
||||
export function taskError(msg: string): never {
|
||||
throw new AbortTaskError(msg);
|
||||
throw new FailTaskError(msg);
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { markPage, sleepMicro, timestamp, waitForLoad } from './utils';
|
||||
import { AbortTaskError, ActionError, GrabError, TryLaterError, VillageNotFound } from './Errors';
|
||||
import { AbortTaskError, ActionError, FailTaskError, GrabError, TryLaterError, VillageNotFound } from './Errors';
|
||||
import { TaskQueueRenderer } from './TaskQueueRenderer';
|
||||
import { createActionHandler } from './Action/ActionController';
|
||||
import { Logger } from './Logger';
|
||||
@ -134,7 +134,7 @@ export class Executor {
|
||||
this.scheduler.clearActions();
|
||||
|
||||
if (err instanceof AbortTaskError) {
|
||||
this.logger.warn('Abort task', task.id, 'MSG', err.message);
|
||||
this.logger.warn('Abort task', task.id, 'msg', err.message);
|
||||
this.scheduler.removeTask(task.id);
|
||||
return;
|
||||
}
|
||||
@ -151,13 +151,19 @@ export class Executor {
|
||||
return;
|
||||
}
|
||||
|
||||
if (err instanceof FailTaskError) {
|
||||
this.logger.error('Fail task', task.id, 'msg', err.message);
|
||||
this.scheduler.removeTask(task.id);
|
||||
return;
|
||||
}
|
||||
|
||||
if (err instanceof GrabError) {
|
||||
this.logger.error('Layout element not found, abort action', err.message);
|
||||
return;
|
||||
}
|
||||
|
||||
if (err instanceof ActionError) {
|
||||
this.logger.error('Abort action', err.message);
|
||||
this.logger.error('Action error', err.message);
|
||||
return;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user