angular - 如何阻止代码流进入Angular 8中的全局错误处理程序
问题描述
我在一个组件中特别需要处理组件本身的错误,但我的项目中也有全局错误处理程序拦截器,所以基本上我希望代码执行在 if 条件下停止,而不是进入错误处理程序。
API 响应返回“状态码:400[Bad request] ”。
下面是我在组件中的代码。
if (error.status === 400) {
this.errorMessage = 'Passcode invalid. Please try again.';
// I want my code to stop here from going into global error handler.
} else if (error.status === 403) {
this.errorMessage = 'You do not have access to this feature. Please contact your system
administrator to proceed.';
} else if (error.status === 500 || error.status === 503) {
this.errorMessage = 'Something went wrong,We are looking to fix it.';
}
this.showError = true;
这是错误处理程序服务中的功能:
handleError(response: HttpErrorResponse) {
if (response.status === 403) {
this.permissionDenied();
} else if (response.status === 500 || response.status === 503) {
this.serviceUnavailable();
} else {
// code goes here and executes below, which i don't want for that specific component.
this.authTokenService.redirectToLogin();
}
}
我附上了一张到底发生了什么的图片:
出现此消息,显然表明 if 条件执行,但用户在此之后立即注销。那就是问题所在。
解决方案
推荐阅读
- identityserver3 - 使用 SustainSys 在 IdentityServer3 中配置多个 SAML2 实例
- python - 当我输入带逗号的数字时,为什么此代码会给我一个错误?
- c# - 如何用`Convert.ToString(someObject);`替换所有出现的`someObject.ToString()`
- c# - 为什么 Firefox 对此 204(无内容)响应有问题?
- r - 使用 MICE 进行多重插补后,如何使用 lm() 对 R 中的子集运行线性回归
- javascript - 来自php数组值的javascript变量声明
- assembly - 汇编 IA-32:添加/减去 32 位有符号值并返回有符号 64 位
- java - 某些 ogg 文件不能在 java 中播放(可能与大小有关?)
- c++ - 整数键映射到头文件中的成员函数指针
- html - 为什么 z-index 被忽略?