【问题标题】:HttpClientModule ( HTTPClient ) Error Handling for Angular 4.3 and aboveAngular 4.3 及更高版本的 HttpClientModule ( HTTPClient ) 错误处理
【发布时间】:2017-12-13 13:19:07
【问题描述】:

我有一个在错误响应中记录请求有效负载的场景,但错误对象不能包含比其默认成员更多的信息。

除了为有效负载创建一个闭包对象并在错误回调中使用它之外,还有什么建议吗?

我怀疑在这个现有的错误类中添加新成员

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

【问题讨论】:

    标签: http httpclient angular5


    【解决方案1】:

    我找到了解决方案。 我们需要拦截错误消息并从中添加访问负载并传递给错误对象。

    error.payload = request.data
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-08-06
      • 1970-01-01
      • 2018-06-26
      • 2014-05-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多