【发布时间】:2019-07-13 00:50:39
【问题描述】:
我正在从 asp.net 核心以 ActionResult 的形式返回自定义错误消息,如下所示:
return NotFound(new { message = "Document file doesn't exist" });
但我看不到如何在角度拦截器中从 catchError 获取消息:
intercept(
request: HttpRequest<any>,
next: HttpHandler
): Observable<HttpEvent<any>> {
return next.handle(this.updateHeader(request)).pipe(
catchError((err: HttpErrorResponse) => {
// Try to refresh token or logout in case refresh wasn't successful
if (err.status === 401) { ... }
...
错误对象如下所示:
error: Blob { size: 61, type: "application/json" }
headers: Object { normalizedNames: Map(0), lazyUpdate: null, lazyInit: lazyInit() }
message: "Http failure response for https://localhost:44357/api/documents/1121: 404 Not Found"
name: "HttpErrorResponse"
ok: false
status: 404
statusText: "Not Found"
url: "https://localhost:44357/api/documents/1121"
<prototype>: Object { ... }
【问题讨论】:
标签: angular asp.net-core-webapi