package com.qmth.boot.core.retrofit.core;

import com.qmth.boot.core.retrofit.config.RetrofitProperties;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class RetrofitInvocationHandler implements InvocationHandler {

    private Object source;

    private RetrofitProperties retrofitProperties;

    public RetrofitInvocationHandler(Object source, RetrofitProperties retrofitProperties) {
        this.source = source;
        this.retrofitProperties = retrofitProperties;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        try {
            return method.invoke(source, args);
        } catch (Throwable e) {
            Throwable cause = e.getCause();
            // Object fallbackObject = getFallbackObject(cause);
            // 熔断逻辑
            // if (cause instanceof RetrofitBlockException && degradeProperty.isEnable() && fallbackObject != null) {
            //     return method.invoke(fallbackObject, args);
            //}
            throw cause;
        }
    }
}
