Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何阻止代码流进入Angular 8中的全局错误处理程序_Angular_Typescript_Angular Http Interceptors - Fatal编程技术网

如何阻止代码流进入Angular 8中的全局错误处理程序

如何阻止代码流进入Angular 8中的全局错误处理程序,angular,typescript,angular-http-interceptors,Angular,Typescript,Angular Http Interceptors,我在一个组件中有一个特殊的需求来处理组件本身的错误,但我的项目中也有全局错误处理程序拦截器,所以基本上我希望代码执行在if条件下停止,而不是进入错误处理程序 API响应返回“状态代码:400[错误请求]” 下面是我在组件中的代码 if (error.status === 400) { this.errorMessage = 'Passcode invalid. Please try again.'; // I want my code to stop here from going in

我在一个组件中有一个特殊的需求来处理组件本身的错误,但我的项目中也有全局错误处理程序拦截器,所以基本上我希望代码执行在if条件下停止,而不是进入错误处理程序

API响应返回“状态代码:400[错误请求]

下面是我在组件中的代码

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();
  }
}
我附上了一张具体发生了什么的图片:

出现此消息,显然表明如果条件执行,但用户会立即注销。这就是问题所在


当API执行失败或未处理的错误导致流进入
handleError
时。你能提供stackblitz演示吗?@PrashantPimpale我认为stackblitz演示不可能展示!那么api响应呢?从邮递员那里试试,检查它返回的内容必须是
500
您想做什么?您可以使用一个服务从全局错误函数发出错误,并在组件中订阅它,这是一个好方法!我会试试看。当你的API执行失败或未处理的错误导致流进入
handleError
时。你能提供stackblitz演示吗?@PrashantPimpale我认为stackblitz演示不可能展示!那么api响应呢?从邮递员那里试试,检查它返回的内容必须是
500
您想做什么?您可以使用一个服务从全局错误函数发出错误,并在组件中订阅它,这是一个好方法!我试试看。