Remove panic from ClientLogin
This commit is contained in:
parent
8a4f704788
commit
afa9507ee2
10
lemmy.go
10
lemmy.go
@ -4,6 +4,7 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
@ -11,6 +12,8 @@ import (
|
||||
"github.com/google/go-querystring/query"
|
||||
)
|
||||
|
||||
var ErrNoToken = errors.New("the server didn't provide a token value in its response")
|
||||
|
||||
// Client is a client for Lemmy's HTTP API
|
||||
type Client struct {
|
||||
client *http.Client
|
||||
@ -40,7 +43,12 @@ func (c *Client) ClientLogin(ctx context.Context, l Login) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
c.Token = lr.JWT.ValueOrZero()
|
||||
|
||||
token, ok := lr.JWT.Value()
|
||||
if !ok || token == "" {
|
||||
return ErrNoToken
|
||||
}
|
||||
c.Token = token
|
||||
return nil
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user