fix(line): close HTTP response body from WithHttpInfo calls
Fix bodyclose linter errors by ensuring resp.Body is closed after all *WithHttpInfo SDK calls. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
9b7fc7aa6c
commit
ad78ba06ea
1 changed files with 7 additions and 1 deletions
|
|
@ -459,10 +459,13 @@ func (c *LINEChannel) Send(ctx context.Context, msg bus.OutboundMessage) ([]stri
|
||||||
if entry, ok := c.replyTokens.LoadAndDelete(msg.ChatID); ok {
|
if entry, ok := c.replyTokens.LoadAndDelete(msg.ChatID); ok {
|
||||||
tokenEntry := entry.(replyTokenEntry)
|
tokenEntry := entry.(replyTokenEntry)
|
||||||
if time.Since(tokenEntry.timestamp) < lineReplyTokenMaxAge {
|
if time.Since(tokenEntry.timestamp) < lineReplyTokenMaxAge {
|
||||||
_, _, err := c.client.WithContext(ctx).ReplyMessageWithHttpInfo(&messaging_api.ReplyMessageRequest{
|
resp, _, err := c.client.WithContext(ctx).ReplyMessageWithHttpInfo(&messaging_api.ReplyMessageRequest{
|
||||||
ReplyToken: tokenEntry.token,
|
ReplyToken: tokenEntry.token,
|
||||||
Messages: []messaging_api.MessageInterface{&textMsg},
|
Messages: []messaging_api.MessageInterface{&textMsg},
|
||||||
})
|
})
|
||||||
|
if resp != nil && resp.Body != nil {
|
||||||
|
resp.Body.Close()
|
||||||
|
}
|
||||||
if err == nil {
|
if err == nil {
|
||||||
logger.DebugCF("line", "Message sent via Reply API", map[string]any{
|
logger.DebugCF("line", "Message sent via Reply API", map[string]any{
|
||||||
"chat_id": msg.ChatID,
|
"chat_id": msg.ChatID,
|
||||||
|
|
@ -566,6 +569,9 @@ func (c *LINEChannel) StartTyping(ctx context.Context, chatID string) (func(), e
|
||||||
|
|
||||||
// classifySDKError maps an SDK HTTP response to the project's sentinel errors.
|
// classifySDKError maps an SDK HTTP response to the project's sentinel errors.
|
||||||
func classifySDKError(resp *http.Response, err error) error {
|
func classifySDKError(resp *http.Response, err error) error {
|
||||||
|
if resp != nil && resp.Body != nil {
|
||||||
|
resp.Body.Close()
|
||||||
|
}
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue