@fivem-ts/shared
Version:
FiveM Typescript wrapper shared part
32 lines (31 loc) • 1.05 kB
TypeScript
/**
* A decorator that wraps a method with error handling logic.
*
* The `@ErrorHandler` decorator catches any errors thrown by the decorated method and
* passes them to the provided error handler function. This allows for centralized error
* handling and custom responses to errors.
*
* @example
* ```ts
*
* function logError(error: unknown): void {
* console.error('An error occurred:', error);
* }
*
* class ExampleClass {
* @ErrorHandler(logError)
* riskyMethod() {
* throw new Error('Something went wrong');
* }
* }
*
* const example = new ExampleClass();
* example.riskyMethod(); // Logs: An error occurred: Error: Something went wrong
* ```
*
* @param handleError A function to handle errors. This function is called with the error
* that was thrown by the decorated method.
*
* @returns A function that can be used as a method decorator.
*/
export declare function ErrorHandler(handleError: (error: unknown) => void): (_target: object, propertyKey: string, descriptor: PropertyDescriptor) => void;