英文:
How to get http error response text in angular 8?
问题
这是要翻译的代码部分:
this.authservice.login.subscribe(res => {
this.router.navigateByUrl('/');
}, err => {
this.error = err; // this err returns "Bad request" instead of backend's response text!?
}));
请注意,我只翻译了代码部分,不包括问题或其他内容。
英文:
this.authservice.login.subscribe(res => {
this.router.navigateByUrl('/');
}, err => {
this.error = err; // this err returns "Bad request" instead of backend's response text!?
}));
Can anyone help me? here in err part I didn't get response text from back-end it shows only "Bad Request" every time.
答案1
得分: 0
添加了错误处理程序。
英文:
import { HttpErrorResponse } from '@angular/common/http';
import { throwError } from 'rxjs';
export class ErrorHandler {
public static handleError(error: HttpErrorResponse) {
return throwError(error.error);
}
}
added error handler.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论