Skip to content

Commit

Permalink
Add non-JSON response handling
Browse files Browse the repository at this point in the history
  • Loading branch information
royroyee committed Feb 29, 2024
1 parent 729f85b commit 8c067a4
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"mime/multipart"
"net/http"
"net/url"
"strings"
)

const (
Expand Down Expand Up @@ -114,6 +115,10 @@ func (ac *AlpaconClient) sendRequest(req *http.Request) ([]byte, error) {
}
defer resp.Body.Close()

if !strings.Contains(resp.Header.Get("Content-Type"), "application/json") {
return nil, fmt.Errorf("Server error or incorrect request detected")
}

respBody, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
Expand Down

0 comments on commit 8c067a4

Please sign in to comment.