fix: resolve err113 lint issues with sentinel errors
This commit is contained in:
@@ -4,6 +4,7 @@ package api
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -12,6 +13,13 @@ import (
|
|||||||
"time"
|
"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.
|
// Client wraps HTTP calls to the chat server API.
|
||||||
type Client struct {
|
type Client struct {
|
||||||
BaseURL string
|
BaseURL string
|
||||||
@@ -64,7 +72,7 @@ func (c *Client) do(method, path string, body any) ([]byte, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if resp.StatusCode >= 400 {
|
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
|
return data, nil
|
||||||
@@ -150,7 +158,7 @@ func (c *Client) PollMessages(afterID string, timeout int) ([]Message, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if resp.StatusCode >= 400 {
|
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.
|
// The server may return an array directly or wrapped.
|
||||||
@@ -218,7 +226,7 @@ func (c *Client) GetMembers(channel string) ([]string, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
// Extract member names from whatever format.
|
// 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
|
return members, nil
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package models
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -23,5 +22,5 @@ func (t *AuthToken) User(ctx context.Context) (*User, error) {
|
|||||||
return ul.GetUserByID(ctx, t.UserID)
|
return ul.GetUserByID(ctx, t.UserID)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, errors.New("user lookup not available")
|
return nil, ErrUserLookupNotAvailable
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package models
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -23,7 +22,7 @@ func (cm *ChannelMember) User(ctx context.Context) (*User, error) {
|
|||||||
return ul.GetUserByID(ctx, cm.UserID)
|
return ul.GetUserByID(ctx, cm.UserID)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, errors.New("user lookup not available")
|
return nil, ErrUserLookupNotAvailable
|
||||||
}
|
}
|
||||||
|
|
||||||
// Channel returns the full Channel for this membership.
|
// Channel returns the full Channel for this membership.
|
||||||
@@ -32,5 +31,5 @@ func (cm *ChannelMember) Channel(ctx context.Context) (*Channel, error) {
|
|||||||
return cl.GetChannelByID(ctx, cm.ChannelID)
|
return cl.GetChannelByID(ctx, cm.ChannelID)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, errors.New("channel lookup not available")
|
return nil, ErrChannelLookupNotAvailable
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,14 @@ package models
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
"errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// ErrUserLookupNotAvailable is returned when the user lookup interface is not set.
|
||||||
|
ErrUserLookupNotAvailable = errors.New("user lookup not available")
|
||||||
|
// ErrChannelLookupNotAvailable is returned when the channel lookup interface is not set.
|
||||||
|
ErrChannelLookupNotAvailable = errors.New("channel lookup not available")
|
||||||
)
|
)
|
||||||
|
|
||||||
// DB is the interface that models use to query the database.
|
// DB is the interface that models use to query the database.
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package models
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -23,5 +22,5 @@ func (s *Session) User(ctx context.Context) (*User, error) {
|
|||||||
return ul.GetUserByID(ctx, s.UserID)
|
return ul.GetUserByID(ctx, s.UserID)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, errors.New("user lookup not available")
|
return nil, ErrUserLookupNotAvailable
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user