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"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
@ -11,6 +12,8 @@ import (
|
|||||||
"github.com/google/go-querystring/query"
|
"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
|
// Client is a client for Lemmy's HTTP API
|
||||||
type Client struct {
|
type Client struct {
|
||||||
client *http.Client
|
client *http.Client
|
||||||
@ -40,7 +43,12 @@ func (c *Client) ClientLogin(ctx context.Context, l Login) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
c.Token = lr.JWT.ValueOrZero()
|
|
||||||
|
token, ok := lr.JWT.Value()
|
||||||
|
if !ok || token == "" {
|
||||||
|
return ErrNoToken
|
||||||
|
}
|
||||||
|
c.Token = token
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user