@perfective/error
Advanced tools
Comparing version 0.2.2 to 0.2.3
import { ExceptionContext } from '../exception/exception-context'; | ||
import { ExceptionTokens } from '../exception/exception-tokens'; | ||
export declare type Panic = () => never; | ||
export declare function throws<E extends Error>(message: string, tokens?: ExceptionTokens, context?: ExceptionContext): never; | ||
export declare function throws<E extends Error>(error: E | string): never; | ||
export declare function panic<E extends Error>(message: string, tokens?: ExceptionTokens, context?: ExceptionContext): Panic; | ||
export declare function panic<E extends Error>(error: E | string): Panic; | ||
export declare function throws(message: string, tokens?: ExceptionTokens, context?: ExceptionContext): never; | ||
export declare function throws<E extends Error>(error: E | (() => E) | string): never; | ||
export declare function panic(message: string, tokens?: ExceptionTokens, context?: ExceptionContext): Panic; | ||
export declare function panic<E extends Error>(error: E | (() => E) | string): Panic; | ||
export declare function rethrows(previous: Error, message: string, tokens?: ExceptionTokens, context?: ExceptionContext): never; | ||
export declare function rethrow(message: string, tokens?: ExceptionTokens, context?: ExceptionContext): (previous: Error) => never; | ||
//# sourceMappingURL=panic.d.ts.map |
@@ -11,2 +11,5 @@ "use strict"; | ||
} | ||
if (typeof error === 'function') { | ||
throw error(); | ||
} | ||
throw new exception_1.Exception(exception_message_1.exceptionMessage(error, tokens), context, null); | ||
@@ -16,3 +19,3 @@ } | ||
function panic(error, tokens = {}, context = {}) { | ||
return () => (error_1.isError(error) ? throws(error) : throws(error, tokens, context)); | ||
return () => ((error_1.isError(error) || typeof error === 'function') ? throws(error) : throws(error, tokens, context)); | ||
} | ||
@@ -19,0 +22,0 @@ exports.panic = panic; |
import { ExceptionContext } from '../exception/exception-context'; | ||
import { ExceptionTokens } from '../exception/exception-tokens'; | ||
export declare type Panic = () => never; | ||
export declare function throws<E extends Error>(message: string, tokens?: ExceptionTokens, context?: ExceptionContext): never; | ||
export declare function throws<E extends Error>(error: E | string): never; | ||
export declare function panic<E extends Error>(message: string, tokens?: ExceptionTokens, context?: ExceptionContext): Panic; | ||
export declare function panic<E extends Error>(error: E | string): Panic; | ||
export declare function throws(message: string, tokens?: ExceptionTokens, context?: ExceptionContext): never; | ||
export declare function throws<E extends Error>(error: E | (() => E) | string): never; | ||
export declare function panic(message: string, tokens?: ExceptionTokens, context?: ExceptionContext): Panic; | ||
export declare function panic<E extends Error>(error: E | (() => E) | string): Panic; | ||
export declare function rethrows(previous: Error, message: string, tokens?: ExceptionTokens, context?: ExceptionContext): never; | ||
export declare function rethrow(message: string, tokens?: ExceptionTokens, context?: ExceptionContext): (previous: Error) => never; | ||
//# sourceMappingURL=panic.d.ts.map |
import { isError } from '../error/error'; | ||
import { Exception, causedBy } from '../exception/exception'; | ||
import { causedBy, Exception } from '../exception/exception'; | ||
import { exceptionMessage } from '../exception/exception-message'; | ||
@@ -8,6 +8,9 @@ export function throws(error, tokens = {}, context = {}) { | ||
} | ||
if (typeof error === 'function') { | ||
throw error(); | ||
} | ||
throw new Exception(exceptionMessage(error, tokens), context, null); | ||
} | ||
export function panic(error, tokens = {}, context = {}) { | ||
return () => (isError(error) ? throws(error) : throws(error, tokens, context)); | ||
return () => ((isError(error) || typeof error === 'function') ? throws(error) : throws(error, tokens, context)); | ||
} | ||
@@ -14,0 +17,0 @@ export function rethrows(previous, message, tokens = {}, context = {}) { |
{ | ||
"name": "@perfective/error", | ||
"version": "0.2.2", | ||
"version": "0.2.3", | ||
"description": "Functions for the Error and other types to handle exceptions", | ||
@@ -30,4 +30,4 @@ "keywords": [ | ||
"exports": { | ||
"import": "dist/mjs/index.js", | ||
"require": "dist/cjs/index.js" | ||
"import": "./dist/mjs/index.js", | ||
"require": "./dist/cjs/index.js" | ||
}, | ||
@@ -34,0 +34,0 @@ "files": [ |
@@ -37,2 +37,4 @@ # Error | ||
— throws a provided error. | ||
* `throws<E extends Error>(error: () => E): never` | ||
— throws an error created by the provided function. | ||
* `throws<E extends Error>(message: string, context: ExceptionContext = {}): never` | ||
@@ -47,2 +49,4 @@ — creates and throws an `Exception` with the given `message` and `context`. | ||
— creates a function that throws a provided error. | ||
* `panic<E extends Error>(error: () => E): Panic` | ||
— creates a function that throws an error created by the provided function. | ||
* `panic<E extends Error>(message: string, context: ExceptionContext = {}): Panic` | ||
@@ -54,5 +58,5 @@ — creates a function that throws an `Exception` with the given `message` and `context`. | ||
* `isError<T>(value: Error | T): value is Error` | ||
— returns `true` when the value is an instance of `Error`. | ||
— returns `true` when the value is an instance of `Error`. | ||
* `isNotError<T>(value: Error | T): value is T` | ||
— returns `true` when the value is not an instance of `Error`. | ||
— returns `true` when the value is not an instance of `Error`. | ||
* [`EvalError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/EvalError): | ||
@@ -62,5 +66,5 @@ * `evalError(message?: string): EvalError` | ||
* `isEvalError<T>(value: EvalError | T): value is EvalError` | ||
— returns `true` when the value is an instance of `EvalError`. | ||
— returns `true` when the value is an instance of `EvalError`. | ||
* `isNotEvalError<T>(value: EvalError | T): value is T` | ||
— returns `true` when the value is not an instance of `EvalError`. | ||
— returns `true` when the value is not an instance of `EvalError`. | ||
* [`RangeError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError): | ||
@@ -70,5 +74,5 @@ * `rangeError(message?: string): RangeError` | ||
* `isRangeError<T>(value: RangeError | T): value is RangeError` | ||
— returns `true` when the value is an instance of `RangeError`. | ||
— returns `true` when the value is an instance of `RangeError`. | ||
* `isNotRangeError<T>(value: RangeError | T): value is T` | ||
— returns `true` when the value is not an instance of `RangeError`. | ||
— returns `true` when the value is not an instance of `RangeError`. | ||
* [`ReferenceError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError): | ||
@@ -78,5 +82,5 @@ * `referenceError(message?: string): ReferenceError` | ||
* `isReferenceError<T>(value: ReferenceError | T): value is ReferenceError` | ||
— returns `true` when the value is an instance of `ReferenceError`. | ||
— returns `true` when the value is an instance of `ReferenceError`. | ||
* `isNotReferenceError<T>(value: ReferenceError | T): value is T` | ||
— returns `true` when the value is not an instance of `ReferenceError`. | ||
— returns `true` when the value is not an instance of `ReferenceError`. | ||
* [`SyntaxError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError): | ||
@@ -86,5 +90,5 @@ * `syntaxError(message?: string): SyntaxError` | ||
* `isSyntaxError<T>(value: SyntaxError | T): value is SyntaxError` | ||
— returns `true` when the value is an instance of `SyntaxError`. | ||
— returns `true` when the value is an instance of `SyntaxError`. | ||
* `isNotSyntaxError<T>(value: SyntaxError | T): value is T` | ||
— returns `true` when the value is not an instance of `SyntaxError`. | ||
— returns `true` when the value is not an instance of `SyntaxError`. | ||
* [`TypeError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError): | ||
@@ -94,4 +98,4 @@ * `typeError(message?: string): TypeError` | ||
* `isTypeError<T>(value: TypeError | T): value is TypeError` | ||
— returns `true` when the value is an instance of `TypeError`. | ||
— returns `true` when the value is an instance of `TypeError`. | ||
* `isNotTypeError<T>(value: TypeError | T): value is T` | ||
— returns `true` when the value is not an instance of `TypeError`. | ||
— returns `true` when the value is not an instance of `TypeError`. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
87294
754
94