Comparing version 2.0.0 to 2.1.0
@@ -25,2 +25,6 @@ declare const INTERNAL: unique symbol; | ||
private [INTERNAL]; | ||
/** | ||
* If the data is an object with a message property, it will be used as the error message | ||
* Otherwise, the error message will be the name of the error and the data as a JSON string | ||
*/ | ||
static readonly DEFAULT_MESSAGE: GetMessage<any>; | ||
@@ -71,2 +75,3 @@ /** | ||
static readonly declareMany: typeof declareMany; | ||
static readonly declareEmpty: typeof declareEmpty; | ||
readonly erreurCause?: Erreur; | ||
@@ -97,2 +102,3 @@ cause?: Error | undefined; | ||
}> | undefined; | ||
declare function declareEmpty(name: string, message?: string | GetMessage<never>): ErreurDeclaration<never>; | ||
declare function declareWithTransform<Data, Params extends readonly any[]>(name: string, transform: (...params: Params) => Data, message?: string | GetMessage<Data>): ErreurDeclaration<Data, Params>; | ||
@@ -99,0 +105,0 @@ declare type CreatorsBase = Record<string, (...args: any[]) => any>; |
@@ -74,3 +74,8 @@ var __defProp = Object.defineProperty; | ||
INTERNAL; | ||
Erreur.DEFAULT_MESSAGE = (data, declaration) => `${declaration.name} ${JSON.stringify(data)}`; | ||
Erreur.DEFAULT_MESSAGE = (data, declaration) => { | ||
if (data && "message" in data && typeof data.message === "string") { | ||
return data.message; | ||
} | ||
return `${declaration.name} ${JSON.stringify(data)}`; | ||
}; | ||
Erreur.wrap = wrap; | ||
@@ -89,2 +94,3 @@ Erreur.wrapAsync = wrapAsync; | ||
Erreur.declareMany = declareMany; | ||
Erreur.declareEmpty = declareEmpty; | ||
function wrap(fn, onError) { | ||
@@ -170,2 +176,5 @@ try { | ||
} | ||
function declareEmpty(name, message) { | ||
return declareWithTransform(name, () => null, message); | ||
} | ||
function declareWithTransform(name, transform, message) { | ||
@@ -172,0 +181,0 @@ return Erreur.declare(name, message).withTransform(transform); |
{ | ||
"name": "erreur", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "Type safe custom errors", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
27358
477