From 04f51c32513f07bbb8f8392715d5524040e2671a Mon Sep 17 00:00:00 2001 From: Behrang Noruzi Niya Date: Sun, 4 Mar 2018 14:40:17 +0330 Subject: [PATCH] Add response parameters to error messages --- bot.go | 6 +++++- types.go | 11 ++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/bot.go b/bot.go index e201944..a0e1f81 100644 --- a/bot.go +++ b/bot.go @@ -79,7 +79,11 @@ func (bot *BotAPI) MakeRequest(endpoint string, params url.Values) (APIResponse, } if !apiResp.Ok { - return apiResp, errors.New(apiResp.Description) + parameters := ResponseParameters{} + if apiResp.Parameters != nil { + parameters = *apiResp.Parameters + } + return apiResp, Error{apiResp.Description, parameters} } return apiResp, nil diff --git a/types.go b/types.go index 4a58287..38bc0f6 100644 --- a/types.go +++ b/types.go @@ -410,7 +410,7 @@ type InlineKeyboardButton struct { SwitchInlineQuery *string `json:"switch_inline_query,omitempty"` // optional SwitchInlineQueryCurrentChat *string `json:"switch_inline_query_current_chat,omitempty"` // optional CallbackGame *CallbackGame `json:"callback_game,omitempty"` // optional - Pay bool `json:"pay,omitempty"` // optional + Pay bool `json:"pay,omitempty"` // optional } // CallbackQuery is data sent when a keyboard button with callback data @@ -771,3 +771,12 @@ type PreCheckoutQuery struct { ShippingOptionID string `json:"shipping_option_id,omitempty"` OrderInfo *OrderInfo `json:"order_info,omitempty"` } + +type Error struct { + Message string + ResponseParameters +} + +func (e Error) Error() string { + return e.Message +}