@@ -16,7 +16,9 @@ func TestClient_DoJSON_Success(t *testing.T) {
1616 server := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
1717 response := map [string ]string {"message" : "success" }
1818 w .Header ().Set ("Content-Type" , "application/json" )
19- json .NewEncoder (w ).Encode (response )
19+ if err := json .NewEncoder (w ).Encode (response ); err != nil {
20+ http .Error (w , err .Error (), http .StatusInternalServerError )
21+ }
2022 }))
2123 defer server .Close ()
2224
@@ -44,7 +46,9 @@ func TestClient_DoJSON_Retry(t *testing.T) {
4446 return
4547 }
4648 response := map [string ]string {"message" : "success" }
47- json .NewEncoder (w ).Encode (response )
49+ if err := json .NewEncoder (w ).Encode (response ); err != nil {
50+ http .Error (w , err .Error (), http .StatusInternalServerError )
51+ }
4852 }))
4953 defer server .Close ()
5054
@@ -66,7 +70,9 @@ func TestClient_DoJSON_Retry(t *testing.T) {
6670func TestClient_DoJSON_ContextCancellation (t * testing.T ) {
6771 server := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
6872 time .Sleep (200 * time .Millisecond )
69- json .NewEncoder (w ).Encode (map [string ]string {"message" : "success" })
73+ if err := json .NewEncoder (w ).Encode (map [string ]string {"message" : "success" }); err != nil {
74+ http .Error (w , err .Error (), http .StatusInternalServerError )
75+ }
7076 }))
7177 defer server .Close ()
7278
@@ -91,7 +97,9 @@ func BenchmarkClient_DoJSON(b *testing.B) {
9197 "extract" : "This is a test extract with some content." ,
9298 "url" : "https://example.com" ,
9399 }
94- json .NewEncoder (w ).Encode (response )
100+ if err := json .NewEncoder (w ).Encode (response ); err != nil {
101+ http .Error (w , err .Error (), http .StatusInternalServerError )
102+ }
95103 }))
96104 defer server .Close ()
97105
0 commit comments