diff --git a/utils/bot/bot.go b/utils/bot/bot.go index 7259c49..7900654 100644 --- a/utils/bot/bot.go +++ b/utils/bot/bot.go @@ -211,7 +211,11 @@ func (b Bot) sendStartMessage(data structs.DataTele) error { func (b Bot) sendHelpMessage(data structs.DataTele) error { messages := "" - botCommands := b.getBotCommands() + botCommands, err := b.getBotCommands() + + if err != nil { + return err + } for _, command := range botCommands.Result { messages += fmt.Sprintf("/%s - %s\n\n", command.Command, command.Description) @@ -222,7 +226,7 @@ func (b Bot) sendHelpMessage(data structs.DataTele) error { return telegram.SendMessage(data) } -func (b Bot) getBotCommands() structs.BotCommands { +func (b Bot) getBotCommands() (*structs.BotCommands, error) { return telegram.GetBotCommands() } diff --git a/utils/middleware/index.go b/utils/middleware/index.go index 81bf165..f4a6488 100644 --- a/utils/middleware/index.go +++ b/utils/middleware/index.go @@ -17,7 +17,8 @@ func Recoverer(next http.Handler) http.Handler { w.WriteHeader(http.StatusOK) resp["status"] = "ERROR" - resp["message"] = rvr.(string) + resp["code"] = "internal_error" + resp["message"] = "Something went wrong" jsonResp, _ := json.Marshal(resp) logEntry := middleware.GetLogEntry(r) diff --git a/utils/telegram/telegram.go b/utils/telegram/telegram.go index cf84fb6..894ab61 100644 --- a/utils/telegram/telegram.go +++ b/utils/telegram/telegram.go @@ -226,12 +226,12 @@ func SetTypingAction(data structs.DataTele) error { return nil } -func GetBotCommands() structs.BotCommands { +func GetBotCommands() (*structs.BotCommands, error) { url := getApiURL("getMyCommands") req, err := http.NewRequest("GET", url, nil) if err != nil { - log.Panic(err) + return nil, err } client := &http.Client{} @@ -239,7 +239,7 @@ func GetBotCommands() structs.BotCommands { res, err := client.Do(req) if err != nil { - log.Panic(err) + return nil, err } defer res.Body.Close() @@ -247,20 +247,21 @@ func GetBotCommands() structs.BotCommands { body, err := ioutil.ReadAll(res.Body) if err != nil { - log.Panic(err) + return nil, err } var botCommands structs.BotCommands err = json.Unmarshal(body, &botCommands) if err != nil { - log.Panic(err) + return nil, err } - if botCommands.Ok == false { - log.Fatalln(string(body)) + if botCommands.Ok { + log.Println("GetBotCommands OK") + + return &botCommands, nil } - log.Println("GetBotCommands OK") - return botCommands + return nil, errors.New(string(body)) }