Skip to content

Commit 080c75e

Browse files
Merge #642
642: Update meilisearch.Connect to return more specific errors r=ja7ad a=bevane # Pull Request ## Related issue Fixes #640 ## What does this PR do? - meilisearch.Connect will now return a more specific error instead of the generic "meilisearch is not connected" which makes it easier to troubleshoot unsuccessful connections ## PR checklist Please check if your PR fulfills the following requirements: - [x] Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)? - [x] Have you read the contributing guidelines? - [x] Have you made sure that the title is accurate and descriptive of the changes? Thank you so much for contributing to Meilisearch! <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Bug Fixes** - Improved error messaging when the Meilisearch service is unavailable, providing clearer feedback if the service cannot be reached during connection attempts. <!-- end of auto-generated comment: release notes by coderabbit.ai --> Co-authored-by: Bevane <[email protected]>
2 parents e3086f5 + b0c85d9 commit 080c75e

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

error.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,4 +186,5 @@ var (
186186
ErrNoSearchRequest = errors.New("no search request provided")
187187
ErrNoFacetSearchRequest = errors.New("no search facet request provided")
188188
ErrConnectingFailed = errors.New("meilisearch is not connected")
189+
ErrMeilisearchNotAvailable = errors.New("meilisearch service is not available")
189190
)

meilisearch.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,14 @@ func New(host string, options ...Option) ServiceManager {
4242
func Connect(host string, options ...Option) (ServiceManager, error) {
4343
meili := New(host, options...)
4444

45-
if !meili.IsHealthy() {
46-
return nil, ErrConnectingFailed
45+
resp, err := meili.HealthWithContext(context.Background())
46+
47+
if err != nil {
48+
return nil, err
49+
}
50+
51+
if resp.Status != "available" {
52+
return nil, ErrMeilisearchNotAvailable
4753
}
4854

4955
return meili, nil

0 commit comments

Comments
 (0)