From 8c067a4e0f4ee84990258ba48d3ff7c32073d306 Mon Sep 17 00:00:00 2001 From: royroyee Date: Thu, 29 Feb 2024 11:51:59 +0900 Subject: [PATCH] Add non-JSON response handling --- client/client.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/client/client.go b/client/client.go index 07e16ab..f8d841a 100644 --- a/client/client.go +++ b/client/client.go @@ -10,6 +10,7 @@ import ( "mime/multipart" "net/http" "net/url" + "strings" ) const ( @@ -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