MCPcopy
hub / github.com/elastic/go-elasticsearch / ExampleResponse_IsError

Function ExampleResponse_IsError

esapi/esapi.response_example_test.go:26–48  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

24)
25
26func ExampleResponse_IsError() {
27 es, _ := elasticsearch.New()
28
29 res, err := es.Info()
30
31 // Handle connection errors
32 //
33 if err != nil {
34 log.Fatalf("ERROR: %v", err)
35 }
36 defer func() { _ = res.Body.Close() }()
37
38 // Handle error response (3xx, 4xx, 5xx)
39 //
40 if res.IsError() {
41 log.Printf("ERROR: %s", res.Status())
42 return
43 }
44
45 // Handle successful response (2xx)
46 //
47 log.Println(res)
48}
49
50func ExampleResponse_Status() {
51 es, _ := elasticsearch.New()

Callers

nothing calls this directly

Calls 5

IsErrorMethod · 0.80
PrintfMethod · 0.80
CloseMethod · 0.65
InfoMethod · 0.45
StatusMethod · 0.45

Tested by

no test coverage detected