Visitar URL original
Angular5 Http error - Cannot parse given error object · Issue #202 · stacktracejs/stacktrace.js · GitHub
Skip to content

Angular5 Http error - Cannot parse given error object #202

Description

@toonborgers

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

Activity

  1. Splaktar commented on Jan 23, 2018

    @Splaktar

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

  2. Splaktar commented on Jan 23, 2018

    @Splaktar

    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 => {
          ...
          }
        }
    
  3. JoeScylla commented on Sep 19, 2018

    @JoeScylla

    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.

  4. johannesjo commented on Jan 10, 2020

    @johannesjo

    @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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions