fix: resolve err113 lint issues with sentinel errors
This commit is contained in:
@@ -4,6 +4,7 @@ package api
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
@@ -12,6 +13,13 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
// ErrHTTPStatus is returned when the server responds with an error status code.
|
||||
ErrHTTPStatus = errors.New("HTTP error")
|
||||
// ErrUnexpectedFormat is returned when the response format is unexpected.
|
||||
ErrUnexpectedFormat = errors.New("unexpected format")
|
||||
)
|
||||
|
||||
// Client wraps HTTP calls to the chat server API.
|
||||
type Client struct {
|
||||
BaseURL string
|
||||
@@ -64,7 +72,7 @@ func (c *Client) do(method, path string, body any) ([]byte, error) {
|
||||
}
|
||||
|
||||
if resp.StatusCode >= 400 {
|
||||
return data, fmt.Errorf("HTTP %d: %s", resp.StatusCode, string(data))
|
||||
return data, fmt.Errorf("%w: %d: %s", ErrHTTPStatus, resp.StatusCode, string(data))
|
||||
}
|
||||
|
||||
return data, nil
|
||||
@@ -150,7 +158,7 @@ func (c *Client) PollMessages(afterID string, timeout int) ([]Message, error) {
|
||||
}
|
||||
|
||||
if resp.StatusCode >= 400 {
|
||||
return nil, fmt.Errorf("HTTP %d: %s", resp.StatusCode, string(data))
|
||||
return nil, fmt.Errorf("%w: %d: %s", ErrHTTPStatus, resp.StatusCode, string(data))
|
||||
}
|
||||
|
||||
// The server may return an array directly or wrapped.
|
||||
@@ -218,7 +226,7 @@ func (c *Client) GetMembers(channel string) ([]string, error) {
|
||||
return nil, err
|
||||
}
|
||||
// Extract member names from whatever format.
|
||||
return nil, fmt.Errorf("unexpected members format: %s", string(data))
|
||||
return nil, fmt.Errorf("%w: members: %s", ErrUnexpectedFormat, string(data))
|
||||
}
|
||||
|
||||
return members, nil
|
||||
|
||||
Reference in New Issue
Block a user