Skip to content

Commit

Permalink
Add more logging to request handling (#2589)
Browse files Browse the repository at this point in the history
  • Loading branch information
MinnDevelopment authored Dec 2, 2023
1 parent cfbace6 commit 8a360d5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/main/java/net/dv8tion/jda/api/requests/Request.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,13 @@ public void onSuccess(T successObj)
return;
done = true;
cleanup();
RestActionImpl.LOG.trace("Scheduling success callback for request with route {}/{}", route.getMethod(), route.getCompiledRoute());
api.getCallbackPool().execute(() ->
{
try (ThreadLocalReason.Closable __ = ThreadLocalReason.closable(localReason);
CallbackContext ___ = CallbackContext.getInstance())
{
RestActionImpl.LOG.trace("Running success callback for request with route {}/{}", route.getMethod(), route.getCompiledRoute());
onSuccess.accept(successObj);
}
catch (Throwable t)
Expand Down Expand Up @@ -151,11 +153,13 @@ public void onFailure(Throwable failException)
return;
done = true;
cleanup();
RestActionImpl.LOG.trace("Scheduling failure callback for request with route {}/{}", route.getMethod(), route.getCompiledRoute());
api.getCallbackPool().execute(() ->
{
try (ThreadLocalReason.Closable __ = ThreadLocalReason.closable(localReason);
CallbackContext ___ = CallbackContext.getInstance())
{
RestActionImpl.LOG.trace("Running failure callback for request with route {}/{}", route.getMethod(), route.getCompiledRoute());
onFailure.accept(failException);
if (failException instanceof Error)
api.handleEvent(new ExceptionEvent(api, failException, false));
Expand Down Expand Up @@ -285,6 +289,7 @@ public boolean isCancelled()

public void handleResponse(@Nonnull Response response)
{
RestActionImpl.LOG.trace("Handling response for request with route {}/{} and code {}", route.getMethod(), route.getCompiledRoute(), response.code);
restAction.handleResponse(response, this);
api.handleEvent(new HttpRequestEvent(this, response));
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/net/dv8tion/jda/api/requests/Response.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import net.dv8tion.jda.api.utils.IOFunction;
import net.dv8tion.jda.api.utils.data.DataArray;
import net.dv8tion.jda.api.utils.data.DataObject;
import net.dv8tion.jda.internal.requests.RestActionImpl;
import net.dv8tion.jda.internal.utils.EntityString;
import net.dv8tion.jda.internal.utils.IOUtil;

Expand Down Expand Up @@ -214,6 +215,7 @@ private <T> Optional<T> parseBody(boolean opt, Class<T> clazz, IOFunction<Buffer
reader.mark(1024);
T t = parser.apply(reader);
this.object = t;
RestActionImpl.LOG.trace("Parsed response body for response on url {}\n{}", rawResponse.request().url(), this.object);
return Optional.ofNullable(t);
}
catch (final Exception e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,15 @@ private void applyBody(Request<?> apiRequest, okhttp3.Request.Builder builder)
body = EMPTY_BODY;

builder.method(method, body);

if (apiRequest.getRawBody() != null)
{
LOG.trace("Sending request on route {}/{} with body\n{}",
method,
apiRequest.getRoute().getCompiledRoute(),
apiRequest.getRawBody()
);
}
}

private void applyHeaders(Request<?> apiRequest, okhttp3.Request.Builder builder)
Expand Down

0 comments on commit 8a360d5

Please sign in to comment.