Fix error when raw error is retrieved#2079
Merged
michalpristas merged 6 commits intoelastic:mainfrom Nov 14, 2022
Merged
Conversation
Contributor
aleksmaus
approved these changes
Nov 14, 2022
| } | ||
|
|
||
| // try decoding detailed error by default | ||
| detailedError := &ErrorT{} |
Contributor
There was a problem hiding this comment.
nit: maybe?
var detailedError ErrorT
| ErrTimeout = errors.New("timeout") | ||
| ErrNotFound = errors.New("not found") | ||
|
|
||
| knownErrorTypes = [3]string{ |
Contributor
There was a problem hiding this comment.
nit: could omit the size (easier to add more elements later without updating the size)
knownErrorTypes = [...]string{
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestErrorTranslation(t *testing.T) { |
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What is the problem this PR solves?
Enrollment or any other operation fails when error returned by elastic is a raw string instead of json
How does this PR solve the problem?
This PR adds ability to parse error either as a ErrorT type or string as a secondary option.
For string it tries to guess error type based on some well known occurrences of Exception names or error messages in retrieved error message.
How to test this PR locally
Disable
detailed_errorsin ES and try everything works.Checklist
CHANGELOG.next.asciidocorCHANGELOG-developer.next.asciidoc.Related issues
Fixes: elastic/elastic-agent#931