Skip to content

Commit 8213ef6

Browse files
committed
return error message on invalid http status
1 parent 2ea0e7d commit 8213ef6

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

client.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ var cache1lock = sync.Mutex{}
3030

3131
func NewClient(baseUrl string) *Client {
3232
return NewClientWith(&Config{
33-
Url: baseUrl,
33+
Url: baseUrl,
3434
LogLevel: LogNothing,
3535
})
3636
}
@@ -324,7 +324,7 @@ func (c *Client) registerSchemaUnderSubject(ctx context.Context, subject, schema
324324
return 0, fmt.Errorf("could not marshal schema registry request: %v", err)
325325
}
326326
httpClient := c.getHttpClient()
327-
var u = fmt.Sprintf("%s/subjects/%s/versions", c.config.Url, url.PathEscape(subject))
327+
var u = fmt.Sprintf("%s/subjects/%s/versions", c.config.Url, url.PathEscape(subject))
328328
j := new(newSchemaResponse)
329329
req, err := http.NewRequest("POST", u, bytes.NewReader(jsonRequest))
330330
if err != nil {
@@ -340,13 +340,14 @@ func (c *Client) registerSchemaUnderSubject(ctx context.Context, subject, schema
340340
if err != nil {
341341
return 0, fmt.Errorf("error while making a http request for registering a new schema: %v", err)
342342
}
343-
if resp.StatusCode != 200 {
344-
return 0, fmt.Errorf(resp.Status)
345-
}
346343
data, err := ioutil.ReadAll(resp.Body)
347344
if err != nil {
348345
return 0, fmt.Errorf("error reading schema registry http response body: %v", err)
349346
}
347+
if resp.StatusCode != 200 {
348+
return 0, fmt.Errorf("error reading schema registry, status: %s, body: %s", resp.Status, string(data))
349+
}
350+
350351
if err := json.Unmarshal(data, &j); err != nil {
351352
return 0, fmt.Errorf("error unmarshaling schema registry response json: %v", err)
352353
}

0 commit comments

Comments
 (0)