@aircall/exception
Advanced tools
Comparing version 0.1.0 to 0.1.1
@@ -11,8 +11,8 @@ declare abstract class Exception extends Error { | ||
interface Schema$7 { | ||
interface Schema$8 { | ||
path: string; | ||
} | ||
declare abstract class FieldException extends Exception { | ||
path: Schema$7['path']; | ||
constructor({ path }: Schema$7, message?: string); | ||
path: Schema$8['path']; | ||
constructor({ path }: Schema$8, message?: string); | ||
toJSON(): { | ||
@@ -27,3 +27,3 @@ path: string; | ||
type StringValidation = 'phoneNumber' | 'email' | 'url' | 'emoji' | 'uuid' | 'regex' | 'cuid' | 'cuid2' | 'ulid' | 'datetime' | 'ip'; | ||
interface Schema$6 { | ||
interface Schema$7 { | ||
path: string; | ||
@@ -45,4 +45,4 @@ validation: StringValidation; | ||
code: string; | ||
validation: Schema$6['validation']; | ||
constructor({ validation, path }: Schema$6, message?: string); | ||
validation: Schema$7['validation']; | ||
constructor({ validation, path }: Schema$7, message?: string); | ||
toJSON(): { | ||
@@ -65,3 +65,3 @@ validation: StringValidation; | ||
*/ | ||
interface Schema$5 { | ||
interface Schema$6 { | ||
path: string; | ||
@@ -74,5 +74,5 @@ received: string; | ||
code: string; | ||
received: Schema$5['received']; | ||
expected: Schema$5['expected']; | ||
constructor({ received, expected, path }: Schema$5, message?: string); | ||
received: Schema$6['received']; | ||
expected: Schema$6['expected']; | ||
constructor({ received, expected, path }: Schema$6, message?: string); | ||
toJSON(): { | ||
@@ -99,3 +99,3 @@ received: string; | ||
*/ | ||
interface Schema$4 { | ||
interface Schema$5 { | ||
path: string; | ||
@@ -108,5 +108,5 @@ type: string; | ||
code: string; | ||
type: Schema$4['type']; | ||
maximum: Schema$4['maximum']; | ||
constructor({ path, type, maximum }: Schema$4, message?: string); | ||
type: Schema$5['type']; | ||
maximum: Schema$5['maximum']; | ||
constructor({ path, type, maximum }: Schema$5, message?: string); | ||
toJSON(): { | ||
@@ -133,3 +133,3 @@ type: string; | ||
*/ | ||
interface Schema$3 { | ||
interface Schema$4 { | ||
path: string; | ||
@@ -142,5 +142,5 @@ type: string; | ||
code: string; | ||
type: Schema$3['type']; | ||
minimum: Schema$3['minimum']; | ||
constructor({ path, type, minimum }: Schema$3, message?: string); | ||
type: Schema$4['type']; | ||
minimum: Schema$4['minimum']; | ||
constructor({ path, type, minimum }: Schema$4, message?: string); | ||
toJSON(): { | ||
@@ -157,3 +157,3 @@ type: string; | ||
type IssueException = InvalidTypeException | TooSmallException | TooBigException | InvalidStringException | FieldException; | ||
interface Schema$2 { | ||
interface Schema$3 { | ||
issues: IssueException[]; | ||
@@ -164,4 +164,4 @@ } | ||
code: string; | ||
issues: Schema$2['issues']; | ||
constructor({ issues }?: Schema$2, message?: string); | ||
issues: Schema$3['issues']; | ||
constructor({ issues }?: Schema$3, message?: string); | ||
addIssue(issue: IssueException): void; | ||
@@ -181,2 +181,28 @@ toJSON(): { | ||
/** | ||
* Represents an exception where the received value is of an invalid type. | ||
* | ||
* @example | ||
* // Role must be either "admin" or "user" | ||
* new InvalidTypeException({ path: "input.role", options: ["admin", "user"]}); | ||
*/ | ||
interface Schema$2 { | ||
path: string; | ||
options: string[]; | ||
received: string; | ||
} | ||
declare class InvalidEnumException extends FieldException { | ||
name: string; | ||
code: string; | ||
options: Schema$2['options']; | ||
constructor({ options, received, path }: Schema$2, message?: string); | ||
toJSON(): { | ||
options: string[]; | ||
path: string; | ||
name: string; | ||
message: string; | ||
code: string; | ||
}; | ||
} | ||
declare class GenericException extends Exception { | ||
@@ -223,2 +249,2 @@ name: string; | ||
export { Exception, FieldException, GenericException, InsufficientPermissionException, InvalidStringException, InvalidTypeException, ResourceNotFoundException, TooBigException, TooSmallException, UserInputException }; | ||
export { Exception, FieldException, GenericException, InsufficientPermissionException, InvalidEnumException, InvalidStringException, InvalidTypeException, ResourceNotFoundException, TooBigException, TooSmallException, UserInputException }; |
@@ -34,3 +34,3 @@ 'use strict'; | ||
validation; | ||
constructor({ validation, path }, message = `Input in "${path}" has failed the "${validation}" validation`) { | ||
constructor({ validation, path }, message = `Invalid ${validation}`) { | ||
super({ path }, message); | ||
@@ -53,3 +53,3 @@ this.validation = validation; | ||
expected; | ||
constructor({ received, expected, path }, message = `Input in "${path}" expected to be "${expected}" but received "${received}"`) { | ||
constructor({ received, expected, path }, message = `Expected ${expected}, received ${received}`) { | ||
super({ path }, message); | ||
@@ -128,2 +128,19 @@ this.received = received; | ||
// src/exceptions/UserInput/InvalidEnumException.ts | ||
var InvalidEnumException = class extends FieldException { | ||
name = "InvalidEnumException"; | ||
code = "0105"; | ||
options; | ||
constructor({ options, received, path }, message = `Invalid enum value. Expected ${options.join(" | ")} but received ${received}`) { | ||
super({ path }, message); | ||
this.options = options; | ||
} | ||
toJSON() { | ||
return { | ||
...super.toJSON(), | ||
options: this.options | ||
}; | ||
} | ||
}; | ||
// src/exceptions/GenericException.ts | ||
@@ -179,2 +196,3 @@ var GenericException = class extends Exception { | ||
exports.InsufficientPermissionException = InsufficientPermissionException; | ||
exports.InvalidEnumException = InvalidEnumException; | ||
exports.InvalidStringException = InvalidStringException; | ||
@@ -181,0 +199,0 @@ exports.InvalidTypeException = InvalidTypeException; |
{ | ||
"name": "@aircall/exception", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"main": "dist/index.js", | ||
@@ -5,0 +5,0 @@ "module": "dist/index.mjs", |
@@ -6,3 +6,3 @@ # Getting started | ||
```bash | ||
npm install @aircall/exception | ||
yarn add @aircall/exception | ||
``` | ||
@@ -9,0 +9,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
24240
589