feat: init
This commit is contained in:
1
node_modules/@poppinss/exception/build/index.d.ts
generated
vendored
Normal file
1
node_modules/@poppinss/exception/build/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export * from './src/exception.ts';
|
||||
44
node_modules/@poppinss/exception/build/index.js
generated
vendored
Normal file
44
node_modules/@poppinss/exception/build/index.js
generated
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
import { format } from "node:util";
|
||||
var Exception = class extends Error {
|
||||
name;
|
||||
status;
|
||||
constructor(message, options) {
|
||||
super(message, options);
|
||||
const ErrorConstructor = this.constructor;
|
||||
this.name = ErrorConstructor.name;
|
||||
this.message = message || ErrorConstructor.message || "";
|
||||
this.status = options?.status || ErrorConstructor.status || 500;
|
||||
const code = options?.code || ErrorConstructor.code;
|
||||
if (code !== void 0) this.code = code;
|
||||
const help = ErrorConstructor.help;
|
||||
if (help !== void 0) this.help = help;
|
||||
Error.captureStackTrace(this, ErrorConstructor);
|
||||
}
|
||||
get [Symbol.toStringTag]() {
|
||||
return this.constructor.name;
|
||||
}
|
||||
toString() {
|
||||
if (this.code) return `${this.name} [${this.code}]: ${this.message}`;
|
||||
return `${this.name}: ${this.message}`;
|
||||
}
|
||||
};
|
||||
var InvalidArgumentsException = class extends Exception {
|
||||
static code = "E_INVALID_ARGUMENTS_EXCEPTION";
|
||||
static status = 500;
|
||||
};
|
||||
var RuntimeException = class extends Exception {
|
||||
static code = "E_RUNTIME_EXCEPTION";
|
||||
static status = 500;
|
||||
};
|
||||
function createError(message, code, status) {
|
||||
return class extends Exception {
|
||||
static message = message;
|
||||
static code = code;
|
||||
static status = status;
|
||||
constructor(args, options) {
|
||||
super(format(message, ...args || []), options);
|
||||
this.name = "Exception";
|
||||
}
|
||||
};
|
||||
}
|
||||
export { Exception, InvalidArgumentsException, RuntimeException, createError };
|
||||
76
node_modules/@poppinss/exception/build/src/exception.d.ts
generated
vendored
Normal file
76
node_modules/@poppinss/exception/build/src/exception.d.ts
generated
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
/**
|
||||
* Create a custom error class with the ability to define the error
|
||||
* code, status, and the help text.
|
||||
*
|
||||
* ```js
|
||||
* export class FileNotFoundException extends Exception {
|
||||
* static status = 500
|
||||
* static code = 'E_FILE_NOT_FOUND'
|
||||
* }
|
||||
*
|
||||
* throw new FileNotFoundException(
|
||||
* `Unable to find file from ${filePath} location`
|
||||
* )
|
||||
* ```
|
||||
*/
|
||||
export declare class Exception extends Error {
|
||||
/**
|
||||
* Define the error metadata as static properties to avoid
|
||||
* setting them repeatedly on the error instance
|
||||
*/
|
||||
static help?: string;
|
||||
static code?: string;
|
||||
static status?: number;
|
||||
static message?: string;
|
||||
/**
|
||||
* Name of the class that raised the exception.
|
||||
*/
|
||||
name: string;
|
||||
/**
|
||||
* Optional help description for the error. You can use it to define additional
|
||||
* human readable information for the error.
|
||||
*/
|
||||
help?: string;
|
||||
/**
|
||||
* A machine readable error code. This will allow the error handling logic
|
||||
* to narrow down exceptions based upon the error code.
|
||||
*/
|
||||
code?: string;
|
||||
/**
|
||||
* A status code for the error. Usually helpful when converting errors
|
||||
* to HTTP responses.
|
||||
*/
|
||||
status: number;
|
||||
constructor(message?: string, options?: ErrorOptions & {
|
||||
code?: string;
|
||||
status?: number;
|
||||
});
|
||||
get [Symbol.toStringTag](): string;
|
||||
toString(): string;
|
||||
}
|
||||
export declare class InvalidArgumentsException extends Exception {
|
||||
static code: string;
|
||||
static status: number;
|
||||
}
|
||||
export declare class RuntimeException extends Exception {
|
||||
static code: string;
|
||||
static status: number;
|
||||
}
|
||||
/**
|
||||
* Helper to create an anonymous error class.
|
||||
*
|
||||
* ```ts
|
||||
*
|
||||
* const E_RESOURCE_NOT_FOUND = createError<[number]>(
|
||||
* 'Unable to find resource with id %d',
|
||||
* 'E_RESOURCE_NOT_FOUND'
|
||||
* )
|
||||
* const id = 1
|
||||
* throw new E_RESOURCE_NOT_FOUND([id])
|
||||
*```
|
||||
*/
|
||||
export declare function createError<T extends any[] = never>(message: string, code: string, status?: number): typeof Exception & T extends never ? {
|
||||
new (args?: any, options?: ErrorOptions): Exception;
|
||||
} : {
|
||||
new (args: T, options?: ErrorOptions): Exception;
|
||||
};
|
||||
Reference in New Issue
Block a user