a library to speed up the development of Fivem scripts and frameworks
fivem-ts - Documentation v0.7.5 • Docs
fivem-ts - Documentation v0.7.5 / Shared / ErrorHandler
ErrorHandler(
handleError
): (_target
,propertyKey
,descriptor
) =>void
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.
• handleError
A function to handle errors. This function is called with the error that was thrown by the decorated method.
Function
A function that can be used as a method decorator.
• _target: unknown
• propertyKey: string
• descriptor: PropertyDescriptor
void
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