From 9d6e221a006b09fb3435a69e7c2a5bc05f96892e Mon Sep 17 00:00:00 2001 From: LeeMyeongJun Date: Wed, 30 Nov 2016 22:07:37 +0900 Subject: [PATCH] add error try catch in all method that use BaseChat.values --- configs.go | 72 +++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 60 insertions(+), 12 deletions(-) diff --git a/configs.go b/configs.go index e67fce2..a2bacd5 100644 --- a/configs.go +++ b/configs.go @@ -227,7 +227,11 @@ type ForwardConfig struct { // values returns a url.Values representation of ForwardConfig. func (config ForwardConfig) values() (url.Values, error) { - v, _ := config.BaseChat.values() + v, err := config.BaseChat.values() + if err != nil { + data := url.Values{} + return data, err + } v.Add("from_chat_id", strconv.FormatInt(config.FromChatID, 10)) v.Add("message_id", strconv.Itoa(config.MessageID)) return v, nil @@ -287,7 +291,11 @@ type AudioConfig struct { // values returns a url.Values representation of AudioConfig. func (config AudioConfig) values() (url.Values, error) { - v, _ := config.BaseChat.values() + v, err := config.BaseChat.values() + if err != nil { + data := url.Values{} + return data, err + } v.Add(config.name(), config.FileID) if config.Duration != 0 { @@ -345,7 +353,11 @@ type DocumentConfig struct { // values returns a url.Values representation of DocumentConfig. func (config DocumentConfig) values() (url.Values, error) { - v, _ := config.BaseChat.values() + v, err := config.BaseChat.values() + if err != nil { + data := url.Values{} + return data, err + } v.Add(config.name(), config.FileID) @@ -376,7 +388,11 @@ type StickerConfig struct { // values returns a url.Values representation of StickerConfig. func (config StickerConfig) values() (url.Values, error) { - v, _ := config.BaseChat.values() + v, err := config.BaseChat.values() + if err != nil { + data := url.Values{} + return data, err + } v.Add(config.name(), config.FileID) @@ -409,7 +425,11 @@ type VideoConfig struct { // values returns a url.Values representation of VideoConfig. func (config VideoConfig) values() (url.Values, error) { - v, _ := config.BaseChat.values() + v, err := config.BaseChat.values() + if err != nil { + data := url.Values{} + return data, err + } v.Add(config.name(), config.FileID) if config.Duration != 0 { @@ -448,7 +468,11 @@ type VoiceConfig struct { // values returns a url.Values representation of VoiceConfig. func (config VoiceConfig) values() (url.Values, error) { - v, _ := config.BaseChat.values() + v, err := config.BaseChat.values() + if err != nil { + data := url.Values{} + return data, err + } v.Add(config.name(), config.FileID) if config.Duration != 0 { @@ -488,7 +512,11 @@ type LocationConfig struct { // values returns a url.Values representation of LocationConfig. func (config LocationConfig) values() (url.Values, error) { - v, _ := config.BaseChat.values() + v, err := config.BaseChat.values() + if err != nil { + data := url.Values{} + return data, err + } v.Add("latitude", strconv.FormatFloat(config.Latitude, 'f', 6, 64)) v.Add("longitude", strconv.FormatFloat(config.Longitude, 'f', 6, 64)) @@ -512,7 +540,11 @@ type VenueConfig struct { } func (config VenueConfig) values() (url.Values, error) { - v, _ := config.BaseChat.values() + v, err := config.BaseChat.values() + if err != nil { + data := url.Values{} + return data, err + } v.Add("latitude", strconv.FormatFloat(config.Latitude, 'f', 6, 64)) v.Add("longitude", strconv.FormatFloat(config.Longitude, 'f', 6, 64)) @@ -538,7 +570,11 @@ type ContactConfig struct { } func (config ContactConfig) values() (url.Values, error) { - v, _ := config.BaseChat.values() + v, err := config.BaseChat.values() + if err != nil { + data := url.Values{} + return data, err + } v.Add("phone_number", config.PhoneNumber) v.Add("first_name", config.FirstName) @@ -558,7 +594,11 @@ type GameConfig struct { } func (config GameConfig) values() (url.Values, error) { - v, _ := config.BaseChat.values() + v, err := config.BaseChat.values() + if err != nil { + data := url.Values{} + return data, err + } v.Add("game_short_name", config.GameShortName) @@ -644,7 +684,11 @@ type ChatActionConfig struct { // values returns a url.Values representation of ChatActionConfig. func (config ChatActionConfig) values() (url.Values, error) { - v, _ := config.BaseChat.values() + v, err := config.BaseChat.values() + if err != nil { + data := url.Values{} + return data, err + } v.Add("action", config.Action) return v, nil } @@ -663,7 +707,11 @@ type EditMessageTextConfig struct { } func (config EditMessageTextConfig) values() (url.Values, error) { - v, _ := config.BaseEdit.values() + v, err := config.BaseEdit.values() + if err != nil { + data := url.Values{} + return data, err + } v.Add("text", config.Text) v.Add("parse_mode", config.ParseMode)