-
Notifications
You must be signed in to change notification settings - Fork 17
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
Harmonize exception handling #296
Conversation
errorParams.put("producer", sourceType.getProducer()); | ||
errorParams.put("model", sourceType.getModel()); | ||
errorParams.put("subject-id", subject.getUser().getLogin()); | ||
errorParams.put("sourceId", sourceRegistrationDto.getSourceId().toString()); | ||
throw new CustomParameterizedException("InvalidRequest", errorParams); | ||
throw new BadRequestException("Cannot find assigned source with sourceId or a source " |
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.
Is this not a conflictexception? E.g. http status code 409?
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 cannot be a conflict request, since we did not get enough data to process this request. This is a situation where we cannot both create a new source, or update source.
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.
Ok understood
* @return {@link Subject} loaded. | ||
*/ | ||
public Subject findOneByLogin(String login) { | ||
Optional<Subject> subject = subjectRepository.findOneWithEagerBySubjectLogin(login); |
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.
Use Optional#orElseThrow()
in these cases
.get()); // we know the list is not empty so calling get() is safe here | ||
throw new InvalidRequestException( | ||
// we know the list is not empty so calling get() is safe here | ||
"Cannot delete a source-type that " + "is being used by project(s)", SOURCE_TYPE, |
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.
Add back the list of projects here? The reduce(String.join).get() can be replaced with collect(Collectors.joining)
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.
Looks good, some small comments
Re-factored error handling in MP. This PR allows to use specific exceptions with a common format and appropriate HTTP Status code and some refactoring where relevant.