Search in sources :

Example 1 with CallbackContext

use of net.dv8tion.jda.internal.requests.CallbackContext in project JDA by DV8FromTheWorld.

the class Request method onSuccess.

public void onSuccess(T successObj) {
    if (done)
        return;
    done = true;
    api.getCallbackPool().execute(() -> {
        try (ThreadLocalReason.Closable __ = ThreadLocalReason.closable(localReason);
            CallbackContext ___ = CallbackContext.getInstance()) {
            onSuccess.accept(successObj);
        } catch (Throwable t) {
            RestActionImpl.LOG.error("Encountered error while processing success consumer", t);
            if (t instanceof Error) {
                api.handleEvent(new ExceptionEvent(api, t, true));
                throw (Error) t;
            }
        }
    });
}
Also used : ExceptionEvent(net.dv8tion.jda.api.events.ExceptionEvent) ThreadLocalReason(net.dv8tion.jda.api.audit.ThreadLocalReason) CallbackContext(net.dv8tion.jda.internal.requests.CallbackContext)

Example 2 with CallbackContext

use of net.dv8tion.jda.internal.requests.CallbackContext in project JDA by DV8FromTheWorld.

the class Request method onFailure.

public void onFailure(Throwable failException) {
    if (done)
        return;
    done = true;
    api.getCallbackPool().execute(() -> {
        try (ThreadLocalReason.Closable __ = ThreadLocalReason.closable(localReason);
            CallbackContext ___ = CallbackContext.getInstance()) {
            onFailure.accept(failException);
            if (failException instanceof Error)
                api.handleEvent(new ExceptionEvent(api, failException, false));
        } catch (Throwable t) {
            RestActionImpl.LOG.error("Encountered error while processing failure consumer", t);
            if (t instanceof Error) {
                api.handleEvent(new ExceptionEvent(api, t, true));
                throw (Error) t;
            }
        }
    });
}
Also used : ExceptionEvent(net.dv8tion.jda.api.events.ExceptionEvent) ThreadLocalReason(net.dv8tion.jda.api.audit.ThreadLocalReason) CallbackContext(net.dv8tion.jda.internal.requests.CallbackContext)

Aggregations

ThreadLocalReason (net.dv8tion.jda.api.audit.ThreadLocalReason)2 ExceptionEvent (net.dv8tion.jda.api.events.ExceptionEvent)2 CallbackContext (net.dv8tion.jda.internal.requests.CallbackContext)2