-
Notifications
You must be signed in to change notification settings - Fork 343
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
done #308
base: main
Are you sure you want to change the base?
done #308
Conversation
if (categoryRepository.existsById(id)) { | ||
categoryRepository.deleteById(id); | ||
} else { | ||
throw new NoSuchElementException("couldn't delete category by id: " + id); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This approach "fails fast" by handling the exception first, reducing the need for nested code. Since an exception ends the method, there's no need for an else clause, making the code cleaner. Let's do it this way everywhere
if (categoryRepository.existsById(id)) { | |
categoryRepository.deleteById(id); | |
} else { | |
throw new NoSuchElementException("couldn't delete category by id: " + id); | |
} | |
if (!categoryRepository.existsById(id)) { | |
categoryRepository.deleteById(id); | |
} | |
throw new NoSuchElementException("Couldn't delete category by id: " + id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well done! 🚀
No description provided.