Skip to content

Commit 589f0a6

Browse files
committed
fix: check HTTP status in ping pong clients
1 parent ed9efbb commit 589f0a6

File tree

3 files changed

+12
-3
lines changed
  • workloads
    • ping-pong-cofide/ping-pong-cofide-client
    • ping-pong-mesh/ping-pong-mesh-client
    • ping-pong/ping-pong-client

3 files changed

+12
-3
lines changed

workloads/ping-pong-cofide/ping-pong-cofide-client/main.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"io"
77
"log/slog"
8+
"net/http"
89
"net/url"
910
"os"
1011
"strconv"
@@ -127,6 +128,9 @@ func ping(client *cofidehttp.Client, serverAddr string, serverPort int) error {
127128
if err != nil {
128129
return err
129130
}
131+
if r.StatusCode != http.StatusOK {
132+
return fmt.Errorf("unexpected status code: %d: %s", r.StatusCode, body[:1024])
133+
}
130134
slog.Info(string(body))
131135
return nil
132136
}

workloads/ping-pong-mesh/ping-pong-mesh-client/main.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package main
22

33
import (
4-
"context"
54
"fmt"
65
"io"
76
"log"
@@ -13,7 +12,7 @@ import (
1312
)
1413

1514
func main() {
16-
if err := run(context.Background(), getEnv()); err != nil {
15+
if err := run(getEnv()); err != nil {
1716
log.Fatal(err)
1817
}
1918
}
@@ -38,7 +37,7 @@ func getEnv() *Env {
3837
}
3938
}
4039

41-
func run(ctx context.Context, env *Env) error {
40+
func run(env *Env) error {
4241
client := &http.Client{
4342
Transport: &http.Transport{},
4443
}
@@ -69,6 +68,9 @@ func ping(client *http.Client, serverAddr, serverPort string) error {
6968
if err != nil {
7069
return err
7170
}
71+
if r.StatusCode != http.StatusOK {
72+
return fmt.Errorf("unexpected status code: %d: %s", r.StatusCode, body[:1024])
73+
}
7274
slog.Info(string(body))
7375
return nil
7476
}

workloads/ping-pong/ping-pong-client/main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,9 @@ func ping(client *http.Client, serverAddr string, serverPort int) error {
217217
if err != nil {
218218
return err
219219
}
220+
if r.StatusCode != http.StatusOK {
221+
return fmt.Errorf("unexpected status code: %d: %s", r.StatusCode, body[:1024])
222+
}
220223
slog.Info(string(body))
221224
return nil
222225
}

0 commit comments

Comments
 (0)