Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Handle error message #3

Merged
merged 2 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ module github.com/henomis/qdrant-go

go 1.20

require github.com/henomis/restclientgo v1.0.5
require github.com/henomis/restclientgo v1.1.0
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
github.com/henomis/restclientgo v1.0.5 h1:xMuznJLagE8nGrmFPyBkzsDztJm2A7uMLNGMBY5iWSg=
github.com/henomis/restclientgo v1.0.5/go.mod h1:xIeTCu2ZstvRn0fCukNpzXLN3m/kRTU0i0RwAbv7Zug=
github.com/henomis/restclientgo v1.1.0 h1:qNhBpTwYXuwfy6SL2EWjbfTrlUw70PZYmqQ4jewdu5E=
github.com/henomis/restclientgo v1.1.0/go.mod h1:xIeTCu2ZstvRn0fCukNpzXLN3m/kRTU0i0RwAbv7Zug=
2 changes: 1 addition & 1 deletion qdrantgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type Client struct {

func New(endpoint, apiKey string) *Client {

restClient := restclientgo.New(endpoint)
restClient := restclientgo.New(endpoint).WithDecodeOnError(true)

if len(apiKey) > 0 {
restClient.SetRequestModifier(func(req *http.Request) *http.Request {
Expand Down
8 changes: 7 additions & 1 deletion response/collectionCollectInfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,11 @@ func (c *CollectionCollectInfo) AcceptContentType() string {
}

func (c *CollectionCollectInfo) Decode(body io.Reader) error {
return json.NewDecoder(body).Decode(c)
err := json.NewDecoder(body).Decode(c)
if err != nil {
return err
}

c.Response.SetStatusMessage()
return nil
}
8 changes: 7 additions & 1 deletion response/collectionCreate.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,11 @@ func (c *CollectionCreate) AcceptContentType() string {
}

func (c *CollectionCreate) Decode(body io.Reader) error {
return json.NewDecoder(body).Decode(c)
err := json.NewDecoder(body).Decode(c)
if err != nil {
return err
}

c.Response.SetStatusMessage()
return nil
}
8 changes: 7 additions & 1 deletion response/collectionDelete.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,11 @@ func (c *CollectionDelete) AcceptContentType() string {
}

func (c *CollectionDelete) Decode(body io.Reader) error {
return json.NewDecoder(body).Decode(c)
err := json.NewDecoder(body).Decode(c)
if err != nil {
return err
}

c.Response.SetStatusMessage()
return nil
}
8 changes: 7 additions & 1 deletion response/collectionList.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,11 @@ func (c *CollectionList) AcceptContentType() string {
}

func (c *CollectionList) Decode(body io.Reader) error {
return json.NewDecoder(body).Decode(c)
err := json.NewDecoder(body).Decode(c)
if err != nil {
return err
}

c.Response.SetStatusMessage()
return nil
}
8 changes: 7 additions & 1 deletion response/collectionUpdate.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,11 @@ func (c *CollectionUpdate) AcceptContentType() string {
}

func (c *CollectionUpdate) Decode(body io.Reader) error {
return json.NewDecoder(body).Decode(c)
err := json.NewDecoder(body).Decode(c)
if err != nil {
return err
}

c.Response.SetStatusMessage()
return nil
}
8 changes: 7 additions & 1 deletion response/indexCreate.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,11 @@ func (c *IndexCreate) AcceptContentType() string {
}

func (c *IndexCreate) Decode(body io.Reader) error {
return json.NewDecoder(body).Decode(c)
err := json.NewDecoder(body).Decode(c)
if err != nil {
return err
}

c.Response.SetStatusMessage()
return nil
}
8 changes: 7 additions & 1 deletion response/pointDelete.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,11 @@ func (p *PointDelete) AcceptContentType() string {
}

func (p *PointDelete) Decode(body io.Reader) error {
return json.NewDecoder(body).Decode(p)
err := json.NewDecoder(body).Decode(p)
if err != nil {
return err
}

p.Response.SetStatusMessage()
return nil
}
8 changes: 7 additions & 1 deletion response/pointGet.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,11 @@ func (p *PointGet) AcceptContentType() string {
}

func (p *PointGet) Decode(body io.Reader) error {
return json.NewDecoder(body).Decode(p)
err := json.NewDecoder(body).Decode(p)
if err != nil {
return err
}

p.Response.SetStatusMessage()
return nil
}
8 changes: 7 additions & 1 deletion response/pointSearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,11 @@ func (p *PointSearch) AcceptContentType() string {
}

func (p *PointSearch) Decode(body io.Reader) error {
return json.NewDecoder(body).Decode(p)
err := json.NewDecoder(body).Decode(p)
if err != nil {
return err
}

p.Response.SetStatusMessage()
return nil
}
8 changes: 7 additions & 1 deletion response/pointUpsert.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,11 @@ func (p *PointUpsert) AcceptContentType() string {
}

func (p *PointUpsert) Decode(body io.Reader) error {
return json.NewDecoder(body).Decode(p)
err := json.NewDecoder(body).Decode(p)
if err != nil {
return err
}

p.Response.SetStatusMessage()
return nil
}
8 changes: 7 additions & 1 deletion response/pointsGet.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,11 @@ func (p *PointsGet) AcceptContentType() string {
}

func (p *PointsGet) Decode(body io.Reader) error {
return json.NewDecoder(body).Decode(p)
err := json.NewDecoder(body).Decode(p)
if err != nil {
return err
}

p.Response.SetStatusMessage()
return nil
}
20 changes: 16 additions & 4 deletions response/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import (
)

type Response struct {
Code int `json:"-"`
Time float64 `json:"time"`
Status string `json:"status"`
RawBody *string `json:"-"`
Code int `json:"-"`
Time float64 `json:"time"`
RawStatus any `json:"status"`
Status string `json:"-"`
RawBody *string `json:"-"`
}

type Detail struct {
Expand Down Expand Up @@ -43,3 +44,14 @@ func (r *Response) SetBody(body io.Reader) error {
func (r *Response) SetHeaders(headers restclientgo.Headers) error {
return nil
}

func (r *Response) SetStatusMessage() {
switch status := r.RawStatus.(type) {
case string:
r.Status = status
case map[string]interface{}:
if errorMessage, ok := status["error"].(string); ok {
r.Status = errorMessage
}
}
}