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.

Callback to all methods triggering a send

See original GitHub issue

At the moment I’m trying to integrate raven-js into our webapp, but I have hit a roadblock. The application is mostly single page, but at some points it navigates to other sites, especially in some error cases. So what I end up with is code similar to this:

try {
  doSomeCrazyThingThatMightFail()
} catch (err) {
  Raven.captureException(e)
  window.location.url = 'my.error.page.com'
}

The issue here is that this fails to report the error, as the sending of the report happens asynchronously. What I’m looking for is something like this:

Raven.captureException(e, function () {
  // We are save the exception was sent over the network
  window.location.url = 'my.error.page.com'
})

Looking at the code/docs I could not find the ability to do this, but maybe I missed something.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:3
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
kamilogorekcommented, Jul 17, 2018

@jmahony not yet, we’ll announce the release somewhere at the end of Q3

2reactions
siassajcommented, Jan 17, 2017

In the meantime for anyone else interested this works, although I can’t say it’s super fantastic:

let capture = (e) => {
  return new Promise((resolve, reject) => {
    Raven.captureException(e);
    let requestEventId = Raven.lastEventId();

    let successFunc = (e) => {
      let responseEventId = e.data.event_id;
      if (requestEventId === responseEventId) {
        window.removeEventListener("ravenSuccess", successFunc);
        resolve();
      };
    };

    let failureFunc = (e) => {
      let responseEventId = e.data.event_id;
      if (requestEventId === responseEventId) {
        window.removeEventListener("ravenFailure", failureFunc);
        reject();
      };
    };

    window.addEventListener("ravenSuccess", successFunc);
    window.addEventListener("ravenFailure", failureFunc);
  });
};
Read more comments on GitHub >

github_iconTop Results From Across the Web

Understanding Callback Methods with Examples - OneSpan
In this example we will explain the concept of creating a callback in four steps: First, Create a callback interface and declare inside...
Read more >
Mastering 'this' in JavaScript: Callbacks and bind(), apply(), call()
A callback function is a lucky function that gets passed into the enclosing higher-order function: The callback function gets executed (called) ...
Read more >
Trigger callback on form submit - javascript - Stack Overflow
The submit event only fires when the user clicks a submit button ( or ) in a form. The event is not raised...
Read more >
Automatically provided arguments in JavaScript callback ...
With callback functions on JavaScript methods, the arguments are automatically passed in by the method itself. Using the Array. forEach()  ...
Read more >
Callback API - Metamug
APIs send data when requested, but callbacks can send data when an event is triggered to the callback url. So the client doesn't...
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