handle timeout errors

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2021-01-19 22:55:24 +03:00
parent d611a6aed5
commit a1a3daa799

11
http.go
View File

@ -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)