Angular 4.3 及更高版本的 HttpClientModule ( HTTPClient ) 错误处理
HttpClientModule ( HTTPClient ) Error Handling for Angular 4.3 and above
我有一个在错误响应时记录请求负载的场景,但错误对象不能包含比其默认成员更多的信息。
除了为有效负载创建闭包对象并将其用于错误回调之外,还有什么建议吗?
我怀疑在这个现有错误中添加新成员Class
export declare class HttpErrorResponse extends HttpResponseBase implements Error {
readonly name: string;
readonly message: string;
readonly error: any | null;
/**
* Errors are never okay, even when the status code is in the 2xx success range.
*/
readonly ok: boolean;
constructor(init: {
error?: any;
headers?: HttpHeaders;
status?: number;
statusText?: string;
url?: string;
});
}
Angular 4.3: HttpClient
我找到了解决方案。
我们需要拦截错误消息并从中添加访问负载并传递给错误对象。
error.payload = request.data
我有一个在错误响应时记录请求负载的场景,但错误对象不能包含比其默认成员更多的信息。
除了为有效负载创建闭包对象并将其用于错误回调之外,还有什么建议吗?
我怀疑在这个现有错误中添加新成员Class
export declare class HttpErrorResponse extends HttpResponseBase implements Error {
readonly name: string;
readonly message: string;
readonly error: any | null;
/**
* Errors are never okay, even when the status code is in the 2xx success range.
*/
readonly ok: boolean;
constructor(init: {
error?: any;
headers?: HttpHeaders;
status?: number;
statusText?: string;
url?: string;
});
}
Angular 4.3: HttpClient
我找到了解决方案。 我们需要拦截错误消息并从中添加访问负载并传递给错误对象。
error.payload = request.data