Refactoring task errors
This commit is contained in:
parent
91684d0bad
commit
950345ffdb
@ -1,15 +1,13 @@
|
|||||||
import { ActionController, registerAction } from './ActionController';
|
import { ActionController, registerAction } from './ActionController';
|
||||||
import { AbortTaskError } from '../Errors';
|
import { AbortTaskError, taskError } from '../Errors';
|
||||||
import { Args } from '../Queue/Args';
|
import { Args } from '../Queue/Args';
|
||||||
import { Task } from '../Queue/TaskProvider';
|
import { Task } from '../Queue/TaskProvider';
|
||||||
|
|
||||||
@registerAction
|
@registerAction
|
||||||
export class ClickButtonAction extends ActionController {
|
export class ClickButtonAction extends ActionController {
|
||||||
async run(args: Args, task: Task): Promise<any> {
|
async run(args: Args, task: Task): Promise<any> {
|
||||||
if (!args.selector) {
|
const selector = args.selector || taskError('No selector');
|
||||||
throw new AbortTaskError('No selector');
|
const el = jQuery(selector);
|
||||||
}
|
|
||||||
const el = jQuery(args.selector);
|
|
||||||
if (el.length === 1) {
|
if (el.length === 1) {
|
||||||
console.log('CLICK BUTTON', el);
|
console.log('CLICK BUTTON', el);
|
||||||
el.trigger('click');
|
el.trigger('click');
|
||||||
|
@ -1,14 +1,12 @@
|
|||||||
import { ActionController, registerAction } from './ActionController';
|
import { ActionController, registerAction } from './ActionController';
|
||||||
import { AbortTaskError } from '../Errors';
|
import { taskError } from '../Errors';
|
||||||
import { Args } from '../Queue/Args';
|
import { Args } from '../Queue/Args';
|
||||||
import { Task } from '../Queue/TaskProvider';
|
import { Task } from '../Queue/TaskProvider';
|
||||||
|
|
||||||
@registerAction
|
@registerAction
|
||||||
export class GoToPageAction extends ActionController {
|
export class GoToPageAction extends ActionController {
|
||||||
async run(args: Args, task: Task): Promise<any> {
|
async run(args: Args, task: Task): Promise<any> {
|
||||||
if (!args.path) {
|
const path = args.path || taskError('Empty path');
|
||||||
throw new AbortTaskError('No path');
|
window.location.assign(path);
|
||||||
}
|
|
||||||
window.location.assign(args.path);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { ActionController, registerAction } from './ActionController';
|
import { ActionController, registerAction } from './ActionController';
|
||||||
import { AbortTaskError, ActionError, TryLaterError } from '../Errors';
|
import { AbortTaskError, ActionError, taskError, TryLaterError } from '../Errors';
|
||||||
import { grabResourceDeposits } from '../Page/SlotBlock';
|
import { grabResourceDeposits } from '../Page/SlotBlock';
|
||||||
import { UpgradeBuildingTask } from '../Task/UpgradeBuildingTask';
|
import { UpgradeBuildingTask } from '../Task/UpgradeBuildingTask';
|
||||||
import { ResourceDeposit } from '../Game';
|
import { ResourceDeposit } from '../Game';
|
||||||
@ -15,10 +15,7 @@ export class UpgradeResourceToLevel extends ActionController {
|
|||||||
throw new ActionError('No deposits');
|
throw new ActionError('No deposits');
|
||||||
}
|
}
|
||||||
|
|
||||||
const villageId = args.villageId;
|
const villageId = args.villageId || taskError('No village id');
|
||||||
if (villageId === undefined) {
|
|
||||||
throw new AbortTaskError('No village id');
|
|
||||||
}
|
|
||||||
|
|
||||||
const requiredLevel = getNumber(args.level);
|
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 {
|
export class VillageNotFound extends Error {
|
||||||
constructor(msg: string = '') {
|
constructor(msg: string = '') {
|
||||||
super(msg);
|
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 {
|
export class ActionError extends Error {
|
||||||
constructor(msg: string = '') {
|
constructor(msg: string = '') {
|
||||||
super(msg);
|
super(msg);
|
||||||
@ -26,16 +36,13 @@ export class AbortTaskError extends Error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class TryLaterError extends Error {
|
export class FailTaskError extends Error {
|
||||||
readonly seconds: number;
|
constructor(msg: string = '') {
|
||||||
|
|
||||||
constructor(seconds: number, msg: string = '') {
|
|
||||||
super(msg);
|
super(msg);
|
||||||
this.seconds = seconds;
|
Object.setPrototypeOf(this, FailTaskError.prototype);
|
||||||
Object.setPrototypeOf(this, TryLaterError.prototype);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function taskError(msg: string): never {
|
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 { 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 { TaskQueueRenderer } from './TaskQueueRenderer';
|
||||||
import { createActionHandler } from './Action/ActionController';
|
import { createActionHandler } from './Action/ActionController';
|
||||||
import { Logger } from './Logger';
|
import { Logger } from './Logger';
|
||||||
@ -134,7 +134,7 @@ export class Executor {
|
|||||||
this.scheduler.clearActions();
|
this.scheduler.clearActions();
|
||||||
|
|
||||||
if (err instanceof AbortTaskError) {
|
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);
|
this.scheduler.removeTask(task.id);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -151,13 +151,19 @@ export class Executor {
|
|||||||
return;
|
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) {
|
if (err instanceof GrabError) {
|
||||||
this.logger.error('Layout element not found, abort action', err.message);
|
this.logger.error('Layout element not found, abort action', err.message);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (err instanceof ActionError) {
|
if (err instanceof ActionError) {
|
||||||
this.logger.error('Abort action', err.message);
|
this.logger.error('Action error', err.message);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user