question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

EventListener can't access wire-level request in case of failure

See original GitHub issue

I’m trying to log the URI of failed requests using an EventListener. The URI may be rewritten by Interceptors and I’m interested in the URI of the wire-level request.

In case of a successful request, the URI of the wire-level request can be obtained by by calling Response.request(). But if the request fails and there is no Response object, there seems to be no way to get this information; Only the original is accessible through Call.request().

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
swankjessecommented, Nov 15, 2018

If you need a quick & dirty fix you can use Call tags and interceptors to hack around this. Here’s a sketch:

public void callOkHttp() {
  Request request = new Request.Builder()
      .url(...)
      .tag(HackWireLevelRequestHolder.class, new HackWireLevelRequestHolder())
      .build();
  ...
}


class HackWireLevelRequestHolder {
  public static final Interceptor INTERCEPTOR = new Interceptor() {
    public Response intercept(Chain chain) throws IOException {
      Request request = chain.request();
      request.tag(HackWireLevelRequestHolder.class).wireLevelRequest = request;
      return chain.proceed(request);
    }
  }

  Request wireLevelRequest = null;
}
0reactions
yschimkecommented, Jan 14, 2022

Just hit this but without the ability to control the creation of the request. Just realised I’m saved by the Call.Factory which I can trivially decorate to set the tag I need.

Same solution just using Call.Factory wrapper instead of an interceptor.

We might want to make Call.Factory usage best practices for clients? Coil, Media3, Retrofit all use it, so it’s standard anyway.

Read more comments on GitHub >

github_iconTop Results From Across the Web

eventlistener can't access variable outside function
but I can't access the read element when trying to attach it to another event listener outside the function. Any idea how to...
Read more >
EventTarget.addEventListener() - Web APIs | MDN
An object that specifies characteristics about the event listener. ... called when the browser // attempts to access the passive property.
Read more >
Using a Request Object Event Listener - AWS Documentation
After the send method on the AWS.Request object is called, the event handler executes when the service object receives an AWS.Response object. For...
Read more >
Uncaught TypeError cannot read property 'addeventlistener' of ...
In JavaScript, a very common error is the Uncaught TypeError Cannot read property 'addeventlistener' of null. This error occurs when JavaScript is not...
Read more >
JavaScript HTML DOM EventListener - W3Schools
Add an event listener that fires when a user clicks a button: ... The addEventListener() method makes it easier to control how the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found