Skip to content

Commit c20a37a

Browse files
author
brain.liu
committed
update handleErrorResp
1 parent 9f57a32 commit c20a37a

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

client.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,17 @@ func (c *Client) handleErrorResp(resp *http.Response) error {
334334
return singleErrRes.Error
335335
}
336336

337+
// 尝试将响应体反序列化为 ErrorResponse 数组
338+
var errResArray []ErrorResponse
339+
err = json.Unmarshal(body, &errResArray)
340+
if err == nil && len(errResArray) > 0 {
341+
// 如果反序列化成功且数组不为空
342+
firstErrRes := errResArray[0]
343+
firstErrRes.Error.HTTPStatus = resp.Status
344+
firstErrRes.Error.HTTPStatusCode = resp.StatusCode
345+
return firstErrRes.Error
346+
}
347+
337348
//errRes.Error.HTTPStatus = resp.Status
338349
//errRes.Error.HTTPStatusCode = resp.StatusCode
339350
//return errRes.Error

image.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ type ImageRequest struct {
8383
Moderation string `json:"moderation,omitempty"`
8484
OutputCompression int `json:"output_compression,omitempty"`
8585
OutputFormat string `json:"output_format,omitempty"`
86+
Watermark *bool `json:"watermark,omitempty"`
8687
}
8788

8889
// ImageResponse represents a response structure for image API.

0 commit comments

Comments
 (0)