2

I want when any one of EvalError, RangeError, ReferenceError, SyntaxError, TypeError, URIError is thrown through my code I want to these error should thrown after an ajex request so that I can get to know analyse the client error logs.

When I went deep, I found that sevral interface are created for these error by extending Error class e.g.

interface TypeError extends Error {
}
interface TypeErrorConstructor {
    new (message?: string): TypeError;
    (message?: string): TypeError;
    prototype: TypeError;
}

declare var TypeError: TypeErrorConstructor;  



interface Error {
    name: string;
    message: string;
}

interface ErrorConstructor {
    new (message?: string): Error;
    (message?: string): Error;
    prototype: Error;
}

declare var Error: ErrorConstructor;

So is there any way to redefine/update these interface defination so before throwing these error it should make an ajex request to the server.

Note: I dont want to use windows.onerror since some other library(rollbar) has own onerror implimentation.

Is it possible to redefine these interface. e.g. I can redefine console.log as follows:

console.log=function(){
   return arguments;
}
3
  • Possible duplicate of Logging Clientside JavaScript Errors on Server Commented Aug 29, 2016 at 6:51
  • that's not javascript, so, not sure how it's relevant to your needs Commented Aug 29, 2016 at 6:52
  • I dont want to use windows.onerror. Is there any way to update these defination? Commented Aug 29, 2016 at 6:56

1 Answer 1

2

I faced same issue , solved it by redefining error class

As follows:

var Error = {
       name: this.name,
       message: this.message,
       toString: function () {
            window.Rollbar.error("Something went wrong", this.message );     
             ......
            return this.message;
       }
   };
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.