fix: resolve mnd lint issues with named constants

This commit is contained in:
user
2026-02-20 03:20:26 -08:00
parent c6c5aaf48e
commit f6ca154315
3 changed files with 30 additions and 10 deletions

View File

@@ -14,6 +14,15 @@ import (
"time"
)
const (
// httpClientTimeout is the default HTTP client timeout in seconds.
httpClientTimeout = 30
// httpStatusErrorThreshold is the minimum status code considered an error.
httpStatusErrorThreshold = 400
// pollTimeoutBuffer is extra seconds added to HTTP timeout beyond the poll timeout.
pollTimeoutBuffer = 5
)
var (
// ErrHTTPStatus is returned when the server responds with an error status code.
ErrHTTPStatus = errors.New("HTTP error")
@@ -33,7 +42,7 @@ func NewClient(baseURL string) *Client {
return &Client{
BaseURL: baseURL,
HTTPClient: &http.Client{
Timeout: 30 * time.Second,
Timeout: httpClientTimeout * time.Second,
},
}
}
@@ -72,7 +81,7 @@ func (c *Client) do(method, path string, body any) ([]byte, error) {
return nil, fmt.Errorf("read body: %w", err)
}
if resp.StatusCode >= 400 {
if resp.StatusCode >= httpStatusErrorThreshold {
return data, fmt.Errorf("%w: %d: %s", ErrHTTPStatus, resp.StatusCode, string(data))
}
@@ -125,7 +134,7 @@ func (c *Client) SendMessage(msg *Message) error {
// PollMessages long-polls for new messages.
func (c *Client) PollMessages(afterID string, timeout int) ([]Message, error) {
// Use a longer HTTP timeout than the server long-poll timeout.
client := &http.Client{Timeout: time.Duration(timeout+5) * time.Second}
client := &http.Client{Timeout: time.Duration(timeout+pollTimeoutBuffer) * time.Second}
params := url.Values{}
if afterID != "" {
@@ -158,7 +167,7 @@ func (c *Client) PollMessages(afterID string, timeout int) ([]Message, error) {
return nil, err
}
if resp.StatusCode >= 400 {
if resp.StatusCode >= httpStatusErrorThreshold {
return nil, fmt.Errorf("%w: %d: %s", ErrHTTPStatus, resp.StatusCode, string(data))
}