Retrofit Multiple Requests Error Origin, determining source
04:49 01 Aug 2015

I've a fragment with multiple Retrofit requests. All the requests in case of error converge in the same onEvent(ErrorEvent event) method. How can I identify which request caused the exception? Should I add a TAG to each request? Maybe inside error logic I can "save" the origin?

EDIT: here my Error callback, SOURCE identify Fragment.class.getSimpleName()

abstract class APICallback implements Callback {

    private final EventBus bus = EventBus.getDefault();

    private final String source;

    public APICallback(String source) {
        this.source = source;
    }

    public abstract void success(T object, Response response);

    private void failure(ErrorAPI errorAPI, String source) {
        bus.post(new ErrorAPIEvent(errorAPI, source));
    }

    @Override
    public void failure(RetrofitError retrofitError) {
        ErrorAPI errorAPI = (ErrorAPI) retrofitError.getBodyAs(ErrorAPI.class);

        if (errorAPI != null)
            failure(errorAPI, source);
        else {
            failure(new ErrorAPI(retrofitError.getMessage()), source);
        }
    }
}
android error-handling httpurlconnection retrofit okhttp