Skip to content

Commit

Permalink
elasticsearch support for wrapped errors
Browse files Browse the repository at this point in the history
  • Loading branch information
3vilhamster committed May 22, 2024
1 parent aa4caf8 commit e1beb94
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
4 changes: 3 additions & 1 deletion common/elasticsearch/client/os2/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"context"
"crypto/tls"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
Expand Down Expand Up @@ -230,7 +231,8 @@ func TestParseError(t *testing.T) {
err := os2Client.parseError(&response)

if !tt.expectError {
if parsedErr, ok := err.(*osError); ok && parsedErr.Details != nil {
var parsedErr *osError
if errors.As(err, &parsedErr) && parsedErr.Details != nil {
assert.Equal(t, tt.expectedErrMsg, parsedErr.Details.Reason, "Error message mismatch for case: %s", tt.name)
} else {
t.Errorf("Failed to assert error reason for case: %s", tt.name)
Expand Down
7 changes: 4 additions & 3 deletions common/elasticsearch/client/v6/client_bulk.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ package v6

import (
"context"
"errors"
"time"

"github.com/olivere/elastic"
Expand Down Expand Up @@ -146,9 +147,9 @@ func convertV6ErrorToGenericError(err error) *bulk.GenericError {
return nil
}
status := bulk.UnknownStatusCode
switch e := err.(type) {
case *elastic.Error:
status = e.Status
var elasticError *elastic.Error
if errors.As(err, &elasticError) {
status = elasticError.Status
}
return &bulk.GenericError{
Status: status,
Expand Down
7 changes: 4 additions & 3 deletions common/elasticsearch/client/v7/client_bulk.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ package v7

import (
"context"
"errors"
"time"

"github.com/olivere/elastic/v7"
Expand Down Expand Up @@ -189,9 +190,9 @@ func convertV7ErrorToGenericError(err error) *bulk.GenericError {
return nil
}
status := bulk.UnknownStatusCode
switch e := err.(type) {
case *elastic.Error:
status = e.Status
var elasticError *elastic.Error
if errors.As(err, &elasticError) {
status = elasticError.Status
}
return &bulk.GenericError{
Status: status,
Expand Down

0 comments on commit e1beb94

Please sign in to comment.