MCPcopy
hub / github.com/larksuite/cli / TestHandleResponse_NonJSONError_502

Function TestHandleResponse_NonJSONError_502

internal/client/response_test.go:354–373  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

352}
353
354func TestHandleResponse_NonJSONError_502(t *testing.T) {
355 resp := newApiRespWithStatus(502, []byte("<html>Bad Gateway</html>"), map[string]string{"Content-Type": "text/html"})
356
357 var out, errOut bytes.Buffer
358 err := HandleResponse(resp, ResponseOptions{Out: &out, ErrOut: &errOut, FileIO: &localfileio.LocalFileIO{}})
359 if err == nil {
360 t.Fatal("expected error for 502 text/html")
361 }
362 got := err.Error()
363 if !strings.Contains(got, "HTTP 502") || !strings.Contains(got, "Bad Gateway") {
364 t.Errorf("expected 'HTTP 502' and 'Bad Gateway' in error, got: %s", got)
365 }
366 var netErr *errs.NetworkError
367 if !errors.As(err, &netErr) {
368 t.Errorf("expected *errs.NetworkError, got %T", err)
369 }
370 if output.ExitCodeOf(err) != output.ExitNetwork {
371 t.Errorf("expected ExitNetwork (%d) for 5xx, got %d", output.ExitNetwork, output.ExitCodeOf(err))
372 }
373}
374
375// TestHandleResponse_JSONErrorWithZeroBodyCodeNotSwallowed pins that an HTTP
376// status error whose JSON body omits a non-zero business code (e.g. 400 +

Callers

nothing calls this directly

Calls 6

ExitCodeOfFunction · 0.92
newApiRespWithStatusFunction · 0.85
HandleResponseFunction · 0.85
AsMethod · 0.80
ErrorMethod · 0.45
ContainsMethod · 0.45

Tested by

no test coverage detected