angular6 - Angular 6 HttpErrorResponse 获取 200 状态
问题描述
此代码正在调用 Jasper 服务器以使用 SAML 身份验证建立连接。当代码执行时,它会跳转到handleError 例程,虽然它是200,但仍然有解析错误。 这是执行代码时的控制台信息
此代码正在调用 Jasper 服务器以使用 SAML 身份验证建立连接。当代码执行时,它会跳转到handleError 例程,虽然它是200,但仍然有解析错误。 这是执行代码时的控制台信息
<p>
<i>
<code>
DOM7011: The code on this page disabled back and forward caching. For more information, see: http://go.microsoft.com/fwlink/?LinkID=291337
report
HTML1300: Navigation occurred.
report
In Report Component init
In connectToJasperconnected
[object Object]
{
[functions]: ,
__proto__: { },
error: { },
headers: { },
message: "Http failure during parsing for THE URL",
name: "HttpErrorResponse",
ok: false,
status: 200,
statusText: "OK",
Symbol(INITIAL_VALUE)_h.bdyrahld8ry: undefined,
Symbol(rxSubscriber)_g.bdyrahld8ry: undefined,
Symbol(rxSubscriber)_i.bdyrahld8ry: undefined,
url: "THE URL"
}
Server Error Status: 200 <-- coming from the error routine
Error Connecting to Jasper Server: [object Object] <-- coming from the error routine defined in component
</i>
<b>Component code</b>
ngOnInit(): void {
console.log('In Report Component init');
this.connectToJasper();
}
connectToJasper() {
this.samlConnectionService.
getSAMLConnection().
subscribe(
data => this.connected = true,
error => console.log('Error Connecting to Jasper Server: ' + error)
);
console.log('In connectToJasperconnected');
}
<b>Service code</b>
jasperSamlURL = 'THE URL';
getSAMLConnection(): Observable<any> {
// return this.httpClient.get<any>(this.jasperSamlURL, { responseType: 'text'})
// return this.httpClient.post<any>(this.jasperSamlURL, { observe: 'response'})
return this.httpClient.get(this.jasperSamlURL, { observe: 'response', responseType: 'text' })
.pipe(
tap(response => {
console.log('Http Response Status: ' + response.status);
console.log('Http Response text: ' + response.statusText);
console.log('Http Response Type: ' + response.type);
console.log('Http Response Body: ' + response.body);
}),
map(response => this.HttpResponseCode = response.status),
catchError(this.handleError)
);
}
public handleError(err) {
if (err instanceof HttpErrorResponse) {
// Server side Error
this.HttpResponseCode = err.status;
console.log(err);
console.log('Server Error Status: ' + err.status);
} else {
// Client side error
this.HttpResponseCode = err.status;
console.log('Client Error Status: ' + err.status);
}
return throwError(err);
}
</code>
解决方案
推荐阅读
- angular - 更新数据表保持过滤器和排序
- c# - 将文本框字符串拆分为数组并按数组索引在标签中显示 C#
- html - 链接正在删除 Http 标头
- ios - 在视图中使用 UIPanGestureRecognizer 时未调用 didSelectItemAt
- php - 我的 PHP 表单实际上并没有发送邮件
- javascript - 如何使用 JSPM 锁定整个依赖关系树?
- node.js - 托管在 firebase 上的 Node.js:使用存储在变量中的密钥更新数据库
- laravel - AssetController.php 第 21 行中的 ErrorException:试图获取非对象的属性
- ios - 如何在 Swift4 上将日期格式化为特定格式?
- css - CSS - 奇怪的边框行为