Bake in thread directives
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -29,6 +30,20 @@ func NewClient(token string) *Client {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Client) redactError(err error) error {
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("%s", c.redact(err.Error()))
|
||||
}
|
||||
|
||||
func (c *Client) redact(text string) string {
|
||||
if c.token == "" {
|
||||
return text
|
||||
}
|
||||
return strings.ReplaceAll(text, c.token, "<telegram-token>")
|
||||
}
|
||||
|
||||
func (c *Client) GetUpdates(ctx context.Context, offset int, timeoutSeconds int) ([]Update, error) {
|
||||
params := map[string]any{
|
||||
"offset": offset,
|
||||
@@ -135,7 +150,7 @@ func (c *Client) DownloadFile(ctx context.Context, filePath string) ([]byte, err
|
||||
}
|
||||
resp, err := c.httpClient.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, c.redactError(err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
|
||||
@@ -173,7 +188,7 @@ func (c *Client) SendPhotoBytes(ctx context.Context, chatID int64, filename stri
|
||||
req.Header.Set("Content-Type", writer.FormDataContentType())
|
||||
resp, err := c.httpClient.Do(req)
|
||||
if err != nil {
|
||||
return Message{}, err
|
||||
return Message{}, c.redactError(err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
|
||||
@@ -219,7 +234,7 @@ func (c *Client) SendDocumentBytes(ctx context.Context, chatID int64, filename s
|
||||
req.Header.Set("Content-Type", writer.FormDataContentType())
|
||||
resp, err := c.httpClient.Do(req)
|
||||
if err != nil {
|
||||
return Message{}, err
|
||||
return Message{}, c.redactError(err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
|
||||
@@ -248,7 +263,7 @@ func (c *Client) postJSON(ctx context.Context, method string, params any, result
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
resp, err := c.httpClient.Do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
return c.redactError(err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
|
||||
|
||||
Reference in New Issue
Block a user