import { ValidationError as yupValidationError } from "yup";
import { RequestError } from "./classes/RequestError";
import { UnknownError } from "./classes/UnknownError";
import { ValidationError } from "./classes/ValidationError";
const errorHandler = (error) => {
    if (error instanceof yupValidationError) {
        throw new ValidationError(error.message);
    }
    if (error instanceof RequestError) {
        throw new RequestError(error.message);
    }
    throw new UnknownError(error.message);
};
const Catch = (target, propertyName, descriptor) => {
    const originalMethod = descriptor.value;
    // Rewrite original method with try/catch wrapper
    descriptor.value = function (...args) {
        try {
            const result = originalMethod.apply(this, args);
            /**
             * For unhandled promise rejections
             */
            if (result && result instanceof Promise) {
                return result.catch((error) => {
                    errorHandler(error);
                });
            }
            return result;
        }
        catch (error) {
            errorHandler(error);
        }
    };
    return descriptor;
};
export { Catch };
//# sourceMappingURL=catch.js.map