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

Harmonize exception handling #296

Merged
merged 17 commits into from
Aug 7, 2018
Merged

Harmonize exception handling #296

merged 17 commits into from
Aug 7, 2018

Conversation

nivemaham
Copy link
Collaborator

@nivemaham nivemaham commented Aug 3, 2018

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.

@nivemaham nivemaham changed the base branch from master to dev August 3, 2018 12:19
@nivemaham nivemaham requested a review from blootsvoets August 6, 2018 13:22
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 "
Copy link
Contributor

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?

Copy link
Collaborator Author

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.

Copy link
Contributor

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);
Copy link
Contributor

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,
Copy link
Contributor

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)

blootsvoets
blootsvoets previously approved these changes Aug 6, 2018
Copy link
Contributor

@blootsvoets blootsvoets left a 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

@nivemaham nivemaham merged commit 5e78c81 into dev Aug 7, 2018
@nivemaham nivemaham deleted the harmonize-exception-handling branch August 7, 2018 11:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants