Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Angular5 Http error - Cannot parse given error object #202

Open
toonborgers opened this issue Jan 16, 2018 · 4 comments
Open

Angular5 Http error - Cannot parse given error object #202

toonborgers opened this issue Jan 16, 2018 · 4 comments

Comments

@toonborgers
Copy link

I'm creating an Angular5 app with Typescript and was trying to add stacktrace-js for proper error handling.

When I was testing my setup using a failing http request (404 response), I get an error from stacktrace-js that the error can't be parsed.

Expected Behavior

The error can be parsed correctly.

Current Behavior

The error can't be parsed.

Steps to Reproduce (for bugs)

Set up an environment as in following gist and start the dev server. When the component does the request and it fails, the error handler gets triggered and the described behaviour occurs.

Gist

Context

I was trying to setup error handling for an angular app

Your Environment

  • stacktrace.js version: 2.0.0 (typings version: 0.0.32)
  • Browser Name and version: Chrome 63.0.3239.132
  • Operating System and version (desktop or mobile): macOS Sierra 10.12.6
  • Angular CLI version: 1.6.3
@Splaktar
Copy link

I am seeing this as well. Interested in the proper way to workaround this or handle it.

@Splaktar
Copy link

Splaktar commented Jan 23, 2018

For now, I'm just not sending these Errors to stacktrace.js:

    // Don't try to send stacktraces of HTTP errors as they are already logged on the server
    // and they cause stacktrace-js to throw an exception.
    if (!error.url && !error.headers) {
      // get the stack trace
      StackTrace.fromError(error).then(stackframes => {
      ...
      }
    }

@JoeScylla
Copy link

With ExtJS i had the same problem.

This should be because in chrome user defined exceptions dont have a stacktrace by default. As there is nothing to parse stacktrace.js throws an error. To get a stacktrace in user definedexceptions you have to use the V8 STacktrace API; see: Error.captureStackTrace().

Example with standard javascript:

function MyError(message) {
	this.message = message;
	
	if (Error.captureStackTrace) {
		Error.captureStackTrace(this, CustomError);
	} else {
		this.stack = (new Error).stack;
	}
}
MyError.prototype = Object.create(Error.prototype);
MyError.prototype.name = "MyError";

For ExtJS i just overwritten the constructor of the default exception.

@johannesjo
Copy link

@JoeScylla not sure about this, but according to this new Error().stack should be always undefined for a couple of browsers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants