all repos — telegram-bot-api @ cb3a14a3b5d4216fd32fd6554cf3477616c697ed

Golang bindings for the Telegram Bot API

fix error handling for uploadFile calls
Denis Orlikhin qbikk@ya.ru
Sat, 08 Dec 2018 21:17:07 +0300
commit

cb3a14a3b5d4216fd32fd6554cf3477616c697ed

parent

5d997a78c879ebd88fc00ae423c28eec33dd3a89

1 files changed, 14 insertions(+), 11 deletions(-)

jump to
M bot.gobot.go

@@ -208,30 +208,33 @@ }

ms.SetupRequest(req) - res, err := bot.Client.Do(req) + resp, err := bot.Client.Do(req) if err != nil { return APIResponse{}, err } - defer res.Body.Close() + defer resp.Body.Close() - bytes, err := ioutil.ReadAll(res.Body) + var apiResp APIResponse + bytes, err := bot.decodeAPIResponse(resp.Body, &apiResp) if err != nil { - return APIResponse{}, err + return apiResp, err } if bot.Debug { log.Printf("Endpoint: %s, response: %s\n", endpoint, string(bytes)) } - var apiResp APIResponse + if !apiResp.Ok { + var parameters ResponseParameters - err = json.Unmarshal(bytes, &apiResp) - if err != nil { - return APIResponse{}, err - } + if apiResp.Parameters != nil { + parameters = *apiResp.Parameters + } - if !apiResp.Ok { - return APIResponse{}, errors.New(apiResp.Description) + return apiResp, Error{ + Message: apiResp.Description, + ResponseParameters: parameters, + } } return apiResp, nil