Angular 2 Client Side Errors

2020-03-26 06:17发布

问题:

I am just new to Typescript and Angular 2 and I was wondering what approach would be best for logging client side errors so that if an issue happened in production I would be able to find out what the method was that failed and what error was thrown.

The backend off the app is written in C# and connected to a SQL Server DB. Data is retrieved via WebAPI Calls.

Any server side errors are currently logged to the DB. I was thinking of writing an Typescript errorLoggingService which would call an ErrorLoggingController API which would then log the Error to the DB?

Does this seem like a sound approach or is there a better way of doing this?

An example current Typescript method I have is below:

public getCustomerData(customerId: number, year: number) {
   let apiUrl = this.myApiMethod;
   let urlConcat = apiUrl + '/' + customerId + '/' + year + '/';

   return this.http.get(urlConcat)
      .map((response: Response) => <boolean> response.json())
      .catch(this.handleError);
}

public handleError(error: Response) {
   console.log(Error Handler Method Hit);
   //this is where I would call to the Error logging service
   // which would make an API call to log the error to db
   //this.errorLoggingService.logClientError("Build Error Message");
   return Observable.throw(error.json() || 'Server Error');
} 

     

回答1:

I ended up using jsnlog - http://jsnlog.com/

Usersnap also looks like a useful tool - https://usersnap.com/e1/classic-008