Skip to content
This repository has been archived by the owner on Dec 13, 2023. It is now read-only.

ApplicationException.Code is replaced with exception classes for each of the codes. #3003

Merged
merged 12 commits into from Jul 7, 2022

Conversation

aravindanr
Copy link
Collaborator

@aravindanr aravindanr commented May 24, 2022

Pull Request type

  • Bugfix
  • Feature
  • Refactoring (no functional changes, no api changes)
  • Build related changes (Please run ./gradlew generateLock saveLock to refresh dependencies)
  • WHOSUSING.md
  • Other (please describe):

Changes in this PR

Refactor ApplicationException.Code to their own exception classes. This makes it easier to catch and process exceptions. Previously, ApplicationException is caught and the catch block contained a if-else block for checking the codes.

Code.NOT_FOUND -> NotFoundException
Code.CONFLICT -> ConflictException
Code.INVALID_INPUT -> IllegalArgumentException
Code.BACKEND_ERROR -> TransientException
Code.INTERNAL_ERROR -> NonTransientException

@aravindanr aravindanr marked this pull request as ready for review July 5, 2022 04:31
@aravindanr aravindanr requested a review from jxu-nflx July 5, 2022 04:31
@aravindanr
Copy link
Collaborator Author

@jxu-nflx The PR has a large footprint. It might be easier to review one commit at a time.

@@ -226,15 +236,15 @@ String toJson(Object value) {
try {
return objectMapper.writeValueAsString(value);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
throw new TransientException("Error serializing to json", e);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be NonTransientException instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Changed to NonTransientException.

}
}

<T> T readValue(String json, Class<T> clazz) {
try {
return objectMapper.readValue(json, clazz);
} catch (IOException e) {
throw new RuntimeException(e);
throw new TransientException("Error serializing json", e);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@aravindanr aravindanr added the type: important Important changes label Jul 7, 2022
@aravindanr aravindanr changed the title Exception refactoring ApplicationException.Code is replaced with exception classes for each of the codes. Jul 7, 2022
@aravindanr aravindanr merged commit 35fea12 into main Jul 7, 2022
@aravindanr aravindanr deleted the exception_refactoring branch July 7, 2022 18:36
pmchung pushed a commit to routific/conductor that referenced this pull request Sep 6, 2023
ApplicationException.Code is replaced with exception classes for each of the codes.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: important Important changes type: maintenance Refactoring
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants