all repos — telegram-bot-api @ 38681a48d156eba3e543508a327e4a0039df5537

Golang bindings for the Telegram Bot API

Merge pull request #153 from behrang/master

Add response parameters to error messages
Syfaro syfaro@huefox.com
Mon, 26 Mar 2018 11:19:46 -0500
commit

38681a48d156eba3e543508a327e4a0039df5537

parent

690363a5f88ea715a2b19aa13727fc12c8cba85a

2 files changed, 15 insertions(+), 2 deletions(-)

jump to
M bot.gobot.go

@@ -79,7 +79,11 @@ log.Printf("%s resp: %s", endpoint, bytes)

} 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
M types.gotypes.go

@@ -410,7 +410,7 @@ CallbackData *string `json:"callback_data,omitempty"` // optional

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 @@ InvoicePayload string `json:"invoice_payload"`

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 +}