Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error management on data integrity errors #2467

Closed
anton-johansson opened this issue Feb 18, 2023 · 2 comments · Fixed by #2643
Closed

Error management on data integrity errors #2467

anton-johansson opened this issue Feb 18, 2023 · 2 comments · Fixed by #2643
Labels
type: enhancement A general enhancement

Comments

@anton-johansson
Copy link

I'm trying to do atomic updates, utilizing the _version (@Version) field. I'm trying to properly handle 409 Conflict, and I see that we get a DataAccessResourceFailureException that only has a message:

method [PUT], host [http://localhost:9200], URI [/my-index/_doc/abc123?refresh=false&version_type=external&version=3], status line [HTTP/1.1 409 Conflict]
{"error":{"root_cause":[{"type":"version_conflict_engine_exception","reason":"[abc123]: version conflict, current version [4] is higher or equal to the one provided [3]","index_uuid":"czrIO6l-Tl-A4qvlM27RyA","shard":"0","index":"my-index"}],"typ
e":"version_conflict_engine_exception","reason":"[abc123]: version conflict, current version [4] is higher or equal to the one provided [3]","index_uuid":"czrIO6l-Tl-A4qvlM27RyA","shard":"0","index":"my-index"},"status":409}

This is really hard to work with. Could we not extend DataAccessResourceFailureException (maybe ElasticsearchResourceFailureException?) that has more information about the failure?

catch (ElasticsearchResourceFailureException e) {
    System.out.println(e.getStatusCode());
    System.out.println(e.getResponseBody());
    System.out.println(e.getError()); // <- could be a parsed Error object or a Map<String, Object>?
}
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Feb 18, 2023
@sothawo
Copy link
Collaborator

sothawo commented Feb 18, 2023

I think it would be better to check the response for a 409 code and then either throw a org.springframework.dao.DataIntegrityViolationException or better a custom class that derives from that an contains the detailed error message (like "[test-id]: version conflict, current version [1] is higher or equal to the one provided [1]").

@sothawo sothawo removed the status: waiting-for-triage An issue we've not yet triaged label Feb 18, 2023
@sothawo sothawo changed the title Error management Error management on data integrity errors Feb 18, 2023
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Feb 18, 2023
@anton-johansson
Copy link
Author

Yeah, that would probably be nice too. As long as I can check specifically for this error without having to do magic string lookups, I'll be happy. :D DataIntegrityViolationException doesn't necessarily feel specific enough?

@sothawo sothawo added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Feb 19, 2023
sothawo added a commit to sothawo/spring-data-elasticsearch that referenced this issue Jul 21, 2023
sothawo added a commit that referenced this issue Jul 21, 2023
Original Pull Request #2643
Closes #2467
@sothawo sothawo added this to the 5.2 M2 (2023.1.0) milestone Jul 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants