Skip to content

Commit 500b396

Browse files
committed
feat: add control for elasticsearch unauthorized
1 parent 697c333 commit 500b396

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

elasticsearch/client/client.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package client
33
import (
44
"github.com/Trendyol/go-pq-cdc-elasticsearch/config"
55
"github.com/elastic/go-elasticsearch/v7"
6+
"github.com/go-playground/errors"
67
)
78

89
func NewClient(config *config.Config) (*elasticsearch.Client, error) {
@@ -21,9 +22,14 @@ func NewClient(config *config.Config) (*elasticsearch.Client, error) {
2122
return nil, err
2223
}
2324

24-
if _, err = client.Ping(); err != nil {
25+
r, err := client.Ping()
26+
if err != nil {
2527
return nil, err
2628
}
2729

30+
if r.StatusCode == 401 {
31+
return nil, errors.New("unauthorized")
32+
}
33+
2834
return client, nil
2935
}

0 commit comments

Comments
 (0)