From a1a3daa799b671ca4d53fa6c238ba65350221f29 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Tue, 19 Jan 2021 22:55:24 +0300 Subject: [PATCH] handle timeout errors Signed-off-by: Vasiliy Tolstov --- http.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/http.go b/http.go index a77a68a..415c0e6 100644 --- a/http.go +++ b/http.go @@ -109,8 +109,19 @@ func (h *httpClient) call(ctx context.Context, addr string, req client.Request, // make the request hrsp, err := h.httpcli.Do(hreq.WithContext(ctx)) if err != nil { + switch err := err.(type) { + case net.Error: + if err.Timeout() { + return errors.Timeout("go.micro.client", err.Error()) + } + case *url.Error: + if err, ok := err.Err.(net.Error); ok && err.Timeout() { + return errors.Timeout("go.micro.client", err.Error()) + } + } return errors.InternalServerError("go.micro.client", err.Error()) } + defer hrsp.Body.Close() return parseRsp(ctx, hrsp, cf, rsp, opts)