Skip to content

Commit

Permalink
chore: simplify error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
brunopacheco1 committed Aug 19, 2024
1 parent 079c0c5 commit e76103a
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class AcceptTermsExceptionMapper implements ExceptionMapper<AcceptTermsEx
@Override
public Response toResponse(AcceptTermsException exception) {
var errorResponse = new ErrorResponse(
"Could not accept terms",
"Terms and Licenses could not be accepted",
BAD_REQUEST.getStatusCode(),
exception.getMessage(),
exception.getWarnings()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
@Getter
public class AcceptTermsException extends RuntimeException {

private static final String MESSAGE = "Terms and Licenses of application %s could not be accepted.";
private static final String MESSAGE = "Terms and conditions could not be accepted.";
private final transient List<ValidationWarning> warnings;

public AcceptTermsException(Long applicationId, List<ValidationWarning> warnings) {
super(String.format(MESSAGE, applicationId));
public AcceptTermsException(List<ValidationWarning> warnings) {
super(MESSAGE);
this.warnings = ofNullable(warnings).orElseGet(List::of);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

public class ApplicationNotFoundException extends RuntimeException {

private static final String MESSAGE = "Application %s not found.";
private static final String MESSAGE = "The application was not found.";

public ApplicationNotFoundException(Long applicationId) {
super(MESSAGE.formatted(applicationId));
public ApplicationNotFoundException() {
super(MESSAGE);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

public class ApplicationNotInCorrectStateException extends RuntimeException {

private static final String MESSAGE = "Application %s is not in correct state: %s.";
private static final String MESSAGE = "The application is not in correct state: %s.";

public ApplicationNotInCorrectStateException(Long id, String state) {
super(MESSAGE.formatted(id, state));
public ApplicationNotInCorrectStateException(String state) {
super(MESSAGE.formatted(state));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
@Getter
public class ApplicationSubmissionException extends RuntimeException {

private static final String MESSAGE = "Application %s could not be submitted.";
private static final String MESSAGE = "The application could not be submitted.";
private final transient List<ValidationWarning> warnings;

public ApplicationSubmissionException(Long applicationId, List<ValidationWarning> warnings) {
super(String.format(MESSAGE, applicationId));
public ApplicationSubmissionException(List<ValidationWarning> warnings) {
super(MESSAGE);
this.warnings = ofNullable(warnings).orElseGet(List::of);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@

package io.github.genomicdatainfrastructure.daam.exceptions;

import static java.lang.String.format;

public class AttachmentTooLargeException extends RuntimeException {

private static final String MESSAGE = "File %s is too big.";
private static final String MESSAGE = "The file %s is too big.";

public AttachmentTooLargeException(String filename) {
super(format(MESSAGE, filename));
super(MESSAGE.formatted(filename));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

public class UserNotApplicantException extends RuntimeException {

private static final String MESSAGE = "User %s is not an applicant for application %s";
private static final String MESSAGE = "The user %s is not an applicant.";

public UserNotApplicantException(Long applicationId, String userId) {
super(MESSAGE.formatted(userId, applicationId));
public UserNotApplicantException(String userId) {
super(MESSAGE.formatted(userId));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,16 @@

package io.github.genomicdatainfrastructure.daam.gateways;

import static java.util.Comparator.comparing;
import static java.util.Optional.ofNullable;

import io.github.genomicdatainfrastructure.daam.exceptions.ApplicationNotFoundException;
import io.github.genomicdatainfrastructure.daam.exceptions.ApplicationNotInCorrectStateException;
import io.github.genomicdatainfrastructure.daam.exceptions.UserNotApplicantException;
import io.github.genomicdatainfrastructure.daam.remote.rems.api.RemsApplicationQueryApi;
import io.github.genomicdatainfrastructure.daam.remote.rems.api.RemsCatalogueItemQueryApi;
import io.github.genomicdatainfrastructure.daam.remote.rems.model.Application;
import io.github.genomicdatainfrastructure.daam.remote.rems.model.Entitlement;
import io.github.genomicdatainfrastructure.daam.remote.rems.model.Application.ApplicationStateEnum;
import io.github.genomicdatainfrastructure.daam.remote.rems.model.ApplicationOverview;
import io.github.genomicdatainfrastructure.daam.remote.rems.model.CatalogueItem;
import io.github.genomicdatainfrastructure.daam.remote.rems.model.Entitlement;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.ws.rs.WebApplicationException;
import org.eclipse.microprofile.config.inject.ConfigProperty;
Expand All @@ -25,6 +22,9 @@
import java.util.List;
import java.util.Set;

import static java.util.Comparator.comparing;
import static java.util.Optional.ofNullable;

@ApplicationScoped
public class RemsApiQueryGateway {

Expand Down Expand Up @@ -54,7 +54,7 @@ public Application retrieveApplication(Long applicationId, String userId) {
);
} catch (WebApplicationException e) {
if (e.getResponse().getStatus() == 404) {
throw new ApplicationNotFoundException(applicationId);
throw new ApplicationNotFoundException();
}
throw e;
}
Expand All @@ -73,12 +73,11 @@ public void checkIfApplicationIsEditableByUser(Long id, String userId) {
var application = retrieveApplication(id, userId);

if (!application.getApplicationApplicant().getUserid().equals(userId)) {
throw new UserNotApplicantException(id, userId);
throw new UserNotApplicantException(userId);
}

if (!EDITABLE_STATES.contains(application.getApplicationState())) {
throw new ApplicationNotInCorrectStateException(
id,
application.getApplicationState().value()
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void acceptTerms(Long id, String userId, AcceptTermsCommand acceptTermsCo
.build())
.toList();

throw new AcceptTermsException(id, warnings);
throw new AcceptTermsException(warnings);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void submitApplication(Long id, String userId) {
.build())
.toList();

throw new ApplicationSubmissionException(id, warnings);
throw new ApplicationSubmissionException(warnings);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ void cannot_accept_terms_when_success_false() {

var expected = ErrorResponse.builder()
.status(400)
.title("Could not accept terms")
.detail("Terms and Licenses of application 44 could not be accepted.")
.title("Terms and Licenses could not be accepted")
.detail("Terms and Licenses could not be accepted.")
.validationWarnings(List.of(
ValidationWarning.builder()
.key("dummy-error")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void cannot_submit_application_due_to_submission_errors() {
var expected = ErrorResponse.builder()
.status(400)
.title("Application could not be submitted")
.detail("Application 44 could not be submitted.")
.detail("The application could not be submitted.")
.validationWarnings(List.of(
ValidationWarning.builder()
.key("Missing")
Expand Down

0 comments on commit e76103a

Please sign in to comment.