Skip to content

Commit 1535b36

Browse files
author
Denis Orlikhin
committed
fix error handling for uploadFile calls
1 parent 5d997a7 commit 1535b36

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

bot.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,14 +224,22 @@ func (bot *BotAPI) UploadFile(endpoint string, params Params, fieldname string,
224224
}
225225

226226
var apiResp APIResponse
227-
228-
err = json.Unmarshal(bytes, &apiResp)
227+
bytes, err := bot.decodeAPIResponse(resp.Body, &apiResp)
229228
if err != nil {
230-
return APIResponse{}, err
229+
return apiResp, err
231230
}
232231

233232
if !apiResp.Ok {
234-
return APIResponse{}, errors.New(apiResp.Description)
233+
var parameters ResponseParameters
234+
235+
if apiResp.Parameters != nil {
236+
parameters = *apiResp.Parameters
237+
}
238+
239+
return apiResp, Error{
240+
Message: apiResp.Description,
241+
ResponseParameters: parameters,
242+
}
235243
}
236244

237245
return apiResp, nil

0 commit comments

Comments
 (0)