UNPKG

pollsky

Version:

Chained Polling Library for Node.js: Friendly API with no external dependencies.

56 lines 2.39 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PollingFailedError = exports.ExceptionOccurredError = exports.AtMostConditionError = exports.AtLeastConditionError = exports.ConditionFunctionError = exports.PollskyError = void 0; /** * ✋ Base class for custom error types. */ class PollskyError extends Error { constructor(message, { timestamp, result }) { super(message); this.timestamp = timestamp; this.result = result; Object.setPrototypeOf(this, PollskyError.prototype); } } exports.PollskyError = PollskyError; class ConditionFunctionError extends PollskyError { constructor(props) { super('Condition is not met - function `conditionFn() returned `false` instead of `true`.', props); this.name = 'ConditionFunctionError'; Object.setPrototypeOf(this, ConditionFunctionError.prototype); } } exports.ConditionFunctionError = ConditionFunctionError; class AtLeastConditionError extends PollskyError { constructor(props) { super('Function `conditionFn()` returned `true` but atLeast timeout has not been called yet.', props); this.name = 'AtLeastConditionError'; Object.setPrototypeOf(this, AtLeastConditionError.prototype); } } exports.AtLeastConditionError = AtLeastConditionError; class AtMostConditionError extends PollskyError { constructor(props) { super('Timeout has called before condition is met.', props); this.name = 'AtMostConditionError'; Object.setPrototypeOf(this, AtMostConditionError.prototype); } } exports.AtMostConditionError = AtMostConditionError; class ExceptionOccurredError extends PollskyError { constructor(errorMsg, props) { super(`During execution of asyncFn() an error was thrown. Message: ${errorMsg}`, props); this.name = 'ExceptionOccurredError'; Object.setPrototypeOf(this, ExceptionOccurredError.prototype); } } exports.ExceptionOccurredError = ExceptionOccurredError; class PollingFailedError extends Error { constructor(failures) { super(`Polling failed after ${failures.length} retries. Details: ${JSON.stringify(failures, null, 2)}`); this.failures = failures; Object.setPrototypeOf(this, PollingFailedError.prototype); } } exports.PollingFailedError = PollingFailedError; //# sourceMappingURL=errors.js.map