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.

add opt-in global error-handling (by default)

See original GitHub issue

this gets redundant on the client:

  request
  .get('/querystring')
  .query('search=Manny')
  .query({ order: 'desc', range: '1..5' })
  .end(function(res){
    if (res.error) return something(res.error)
  });

ideally you opt in with something similar to:

request.on('error', function(err){

});

though this would be a bit of a hack since we have no .error(fn) to opt-into http errors in the first place. Arguably global handling is an anti-pattern but worth thinking about

Issue Analytics

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

github_iconTop GitHub Comments

5reactions
apsavincommented, Dec 21, 2015

An example of quick and dirty workaround:

const end = superagent.Request.prototype.end;
superagent.Request.prototype.end = function (callback) {
  return end.call(this, (error, response) => {
    if (response.unauthorized) {
      // handle the error here, for example:
      // window.location = '/login'
    } else {
      callback(error, response);
    }
  });
};
0reactions
bouchercommented, Jan 28, 2016

I believe .end is not supported by superagent-defaults.

Read more comments on GitHub >

github_iconTop Results From Across the Web

add opt-in global error-handling (by default) #165 - GitHub
A great use case for this in-browser would be global handling of 401 errors to force the user to sign in again.
Read more >
Handle errors in ASP.NET Core | Microsoft Learn
NET Core apps enable the developer exception page by default when both: ... UseExceptionHandler adds the exception handling middleware in ...
Read more >
Global Error Handling in ASP.NET Core Web API - Code Maze
In this article, we are going to handle errors by using a try-catch block first and then rewrite our code by using built-in...
Read more >
Error Handling for REST with Spring - Baeldung
This tutorial will illustrate how to implement Exception Handling with Spring for a REST API. We'll also get a bit of historical overview...
Read more >
Complete Guide to Exception Handling in Spring Boot
Spring Boot's Default Exception Handling Mechanism ... Spring Boot provides some properties with which we can add the exception message, ...
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