Skip to content

Commit ea0c702

Browse files
committed
fix(v2): http biz error should unmarshal JSON
1 parent ba79449 commit ea0c702

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

v2/api_notification_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func TestWebhookSignedError(t *testing.T) {
8686
mbText := NewMsgBuffer(MsgText)
8787
mbText.Text("hello sign").WithSign("LIpnNexV7rwOyOebKoqSdb", time.Now().Unix())
8888
resp, err := bot.PostNotification(t.Context(), mbText.Build())
89-
assert.NoError(t, err)
89+
assert.Error(t, err)
9090
assert.Zero(t, resp.StatusCode)
9191
assert.Equal(t, "sign match fail or timestamp is not within one hour from current time", resp.Msg)
9292
}

v2/http.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ func (bot Bot) PerformAPIRequest(
7373
bot.httpErrorLog(ctx, prefix, "read body failed", err)
7474
return err
7575
}
76+
// read response content
77+
err = json.Unmarshal(buffer, &output)
78+
if err != nil {
79+
bot.httpErrorLog(ctx, prefix, "decode body failed", err)
80+
return err
81+
}
7682
// read error code
7783
var dummyOutput DummyResponse
7884
err = json.Unmarshal(buffer, &dummyOutput)
@@ -81,11 +87,6 @@ func (bot Bot) PerformAPIRequest(
8187
bot.logger.Log(ctx, LogLevelError, apiError.Error())
8288
return apiError
8389
}
84-
// read response content
85-
err = json.Unmarshal(buffer, &output)
86-
if err != nil {
87-
bot.httpErrorLog(ctx, prefix, "decode body failed", err)
88-
}
8990
return err
9091
}
9192

0 commit comments

Comments
 (0)