mirror of
https://github.com/kemko/nomad.git
synced 2026-01-01 16:05:42 +03:00
api: return error when LicenseGet status is not 200 (#11644)
This commit is contained in:
3
.changelog/11644.txt
Normal file
3
.changelog/11644.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
```release-note:improvement
|
||||
api: Improve error message returned by `Operator.LicenseGet`
|
||||
```
|
||||
@@ -3,6 +3,7 @@ package api
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"strconv"
|
||||
@@ -338,6 +339,11 @@ func (op *Operator) LicenseGet(q *QueryOptions) (*LicenseReply, *QueryMeta, erro
|
||||
return nil, nil, errors.New("Nomad Enterprise only endpoint")
|
||||
}
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
body, _ := io.ReadAll(resp.Body)
|
||||
return nil, nil, fmt.Errorf("Unexpected response code: %d (%s)", resp.StatusCode, body)
|
||||
}
|
||||
|
||||
err = json.NewDecoder(resp.Body).Decode(&reply)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
|
||||
28
api/operator_ent_test.go
Normal file
28
api/operator_ent_test.go
Normal file
@@ -0,0 +1,28 @@
|
||||
//go:build ent
|
||||
// +build ent
|
||||
|
||||
package api
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestOperator_LicenseGet(t *testing.T) {
|
||||
t.Parallel()
|
||||
c, s, _ := makeACLClient(t, nil, nil)
|
||||
defer s.Stop()
|
||||
|
||||
operator := c.Operator()
|
||||
|
||||
// Make authenticated request.
|
||||
_, _, err := operator.LicenseGet(nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Make unauthenticated request.
|
||||
c.SetSecretID("")
|
||||
_, _, err = operator.LicenseGet(nil)
|
||||
require.Error(t, err)
|
||||
require.Contains(t, err.Error(), "403")
|
||||
}
|
||||
Reference in New Issue
Block a user