Asp.net web api NativeScript-未通过NotFound()上的修补程序从后端获得任何响应

Asp.net web api NativeScript-未通过NotFound()上的修补程序从后端获得任何响应,asp.net-web-api,nativescript,backend,Asp.net Web Api,Nativescript,Backend,在我的后端,我得到了两种可能的反应 第一个: return Ok(new { Message = "email_confirmed" }); 第二个: return NotFound(); 在我的前端我得到了这个: let url: string = "http://10.0.2.2:53286/api/Home/AccountValidation?codeActivation=" + this.code; this.http.patch(url, { }

在我的后端,我得到了两种可能的反应

第一个:

return Ok(new { Message = "email_confirmed" });
第二个:

return NotFound();
在我的前端我得到了这个:

let url: string = "http://10.0.2.2:53286/api/Home/AccountValidation?codeActivation=" + this.code;

        this.http.patch(url, {

        }).subscribe((res) => {
            console.log(JSON.stringify(res));

            if(res.status != 404) {
                alert({title: "Sistema 3 Esferas", message: "¡Tu cuenta ha sido activada satisfactoriamente! :)", okButtonText: "¡Entendido!"});
                this.router.navigate(["/Miembro"]);
            } else {
                this.btnEnabled = true;
                alert({title: "Sistema 3 Esferas", message: "Has introducido un código inválido. :(", okButtonText: "Entiendo..."});
            }
        });
如果后端到达
Ok()
,则执行
If
,并且一切正常。 但是,如果我的后端到达第二个返回,即
NotFound()
1,则什么也不会发生。您可以在订阅()的开头看到这个
日志

那么,如果返回
NotFound()
,则日志上不会显示任何内容。这几乎就像从未执行过订阅一样


为什么会这样

您需要添加catch处理程序来捕获除
200(OK)
之外的所有其他响应,因为它们被视为错误,如下所示-

this.http.patch(url, {

    }).subscribe((res) => {
        console.log(JSON.stringify(res));
            alert({title: "Sistema 3 Esferas", message: "¡Tu cuenta ha sido activada satisfactoriamente! :)", okButtonText: "¡Entendido!"});
            this.router.navigate(["/Miembro"]);
    }).catch(this.handleError);
};

private handleError(error: any) {
    let errMsg = (error.message) ? error.message :
        error.status ? `${error.status} - ${error.statusText}` : 'Server error';
    console.error(errMsg);

    this.btnEnabled = true;
            alert({title: "Sistema 3 Esferas", message: "Has introducido un código inválido. :(", okButtonText: "Entiendo..."});
}

有关更多信息,请参阅。

您需要添加catch处理程序来捕获除
200(OK)
之外的所有其他响应,因为它们被视为错误,如下所示-

this.http.patch(url, {

    }).subscribe((res) => {
        console.log(JSON.stringify(res));
            alert({title: "Sistema 3 Esferas", message: "¡Tu cuenta ha sido activada satisfactoriamente! :)", okButtonText: "¡Entendido!"});
            this.router.navigate(["/Miembro"]);
    }).catch(this.handleError);
};

private handleError(error: any) {
    let errMsg = (error.message) ? error.message :
        error.status ? `${error.status} - ${error.statusText}` : 'Server error';
    console.error(errMsg);

    this.btnEnabled = true;
            alert({title: "Sistema 3 Esferas", message: "Has introducido un código inválido. :(", okButtonText: "Entiendo..."});
}
有关更多信息,请参阅