问题描述
我对Typescript和Angular 2还是陌生的,我想知道哪种方法最适合记录客户端错误,以便如果在生产中发生问题,我将能够找出失败的方法和错误.被扔了.
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.
应用程序的后端用C#编写,并连接到SQL Server DB.通过WebAPI调用检索数据.
The backend off the app is written in C# and connected to a SQL Server DB. Data is retrieved via WebAPI Calls.
任何服务器端错误当前都记录到数据库中.我正在考虑编写一个Typescript errorLoggingService,它将调用ErrorLoggingController API,然后将错误记录到数据库中?
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?
下面是我当前使用的Typescript方法的示例:
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');
}
推荐答案
我最终使用了jsnlog- http://jsnlog. com/
I ended up using jsnlog - http://jsnlog.com/
Usersnap也看起来像是有用的工具- https://usersnap.com/e1/classic-008
Usersnap also looks like a useful tool - https://usersnap.com/e1/classic-008
这篇关于Angular 2客户端错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!