Base solution for your next web application
Open Closed

Angular2 catch error code #7942


User avatar
0
dev.touchpoint created

Hi support team, I'm using ASP.NET Core , Angular, v6.9.0.0 project.

I want to catch the error code like image shown below:

Here are my code:

When I try to use err.code, the result is undefined.

Thanks, Kenny.


4 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team

    Try the code below, but the message box in the screenshot above is handled by abpHttpInterceptor.

    https://github.com/aspnetboilerplate/abp-ng2-module/blob/master/src/abpHttpInterceptor.ts#L152

    this._Service.delete().subscribe(() => {
    
    }, (error: any) => {
    	let responseObj = JSON.parse(error.response);
    	let f = responseObj as IAjaxResponse;
    });
    
  • User Avatar
    0
    dev.touchpoint created

    Hi maliming,

    Thank you for the answer, it solved my question.

    Thanks, Kenny.

  • User Avatar
    0
    dev.touchpoint created

    Hi support team,

    This module is no more in v8.8.0, so is there any other way to catch the error?

    Thanks, Kenny.

  • User Avatar
    0
    dev.touchpoint created

    I found a way to catch error, now can straight away get the error code after parsed to JSON:

    const parsedObj = JSON.parse(error.response);
    if (parsedObj.error.code !== 1) {
        this.message.error(this.l('ContactAdmin'));
    }
    

    Thanks, Kenny.