]> git.giacomolli.uk - onechat/blobdiff - telegram_api.go
Separate returns from longer statement blocks
[onechat] / telegram_api.go
index 24f02ac344954b52f752947f64feeba107c1d7a6..7b9457f6d207dc6abeb03fcd926e6ed5916d4aff 100644 (file)
@@ -163,7 +163,7 @@ func (b *TelegramAPI) call(ctx context.Context, timeout time.Duration, method st
        data, err := io.ReadAll(io.LimitReader(response.Body, telegramAnswerBytes))
        err = errors.Join(err, response.Body.Close())
        if err != nil {
        data, err := io.ReadAll(io.LimitReader(response.Body, telegramAnswerBytes))
        err = errors.Join(err, response.Body.Close())
        if err != nil {
-               return b.networkError("the answer broke off", err, timeout)
+               return b.networkError("answer cut off", err, timeout)
        }
 
        var answer TelegramAnswer
        }
 
        var answer TelegramAnswer
@@ -176,7 +176,7 @@ func (b *TelegramAPI) call(ctx context.Context, timeout time.Duration, method st
        }
 
        if err != nil {
        }
 
        if err != nil {
-               return b.networkError("the answer is not valid JSON", err, timeout)
+               return b.networkError("invalid JSON", err, timeout)
        }
 
        if !answer.OK {
        }
 
        if !answer.OK {
@@ -194,7 +194,7 @@ func (b *TelegramAPI) call(ctx context.Context, timeout time.Duration, method st
 
        err = json.Unmarshal(answer.Result, result)
        if err != nil {
 
        err = json.Unmarshal(answer.Result, result)
        if err != nil {
-               return b.networkError("the result is not valid", err, timeout)
+               return b.networkError("invalid result", err, timeout)
        }
 
        return nil
        }
 
        return nil
@@ -240,10 +240,10 @@ func (e *TelegramNetworkError) Error() string {
 }
 
 // TelegramError is an answer of the Bot API that tells of a failure. Its text
 }
 
 // TelegramError is an answer of the Bot API that tells of a failure. Its text
-// gives the HTTP status and the description, such as "Telegram answered 502 Bad
-// Gateway". RetryAfter is the wait that the Bot API asks for after HTTP 429.
-// Refused tells that the answer is a Bot API answer with ok false, not a page
-// of a proxy or of a server error.
+// gives the HTTP status and the description, such as "502 Bad Gateway".
+// RetryAfter is the wait that the Bot API asks for after HTTP 429. Refused
+// tells that the answer is a Bot API answer with ok false, not a page of a
+// proxy or of a server error.
 type TelegramError struct {
        Status      int
        Description string
 type TelegramError struct {
        Status      int
        Description string
@@ -252,7 +252,7 @@ type TelegramError struct {
 }
 
 func (e *TelegramError) Error() string {
 }
 
 func (e *TelegramError) Error() string {
-       return fmt.Sprintf("Telegram answered %d %s", e.Status, e.Description)
+       return fmt.Sprintf("%d %s", e.Status, e.Description)
 }
 
 // TelegramUpdate is one update of getUpdates. Message is nil for the kinds of
 }
 
 // TelegramUpdate is one update of getUpdates. Message is nil for the kinds of