Skip to content

Commit

Permalink
Use validation bundle formatting for user errors during user profile …
Browse files Browse the repository at this point in the history
…initial submission or edit
  • Loading branch information
ryanrdoherty committed Aug 5, 2024
1 parent b857cf0 commit 4fc6683
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.gusdb.wdk.model.user.UserPreferences;
import org.gusdb.wdk.service.UserBundle;
import org.gusdb.wdk.service.formatter.UserFormatter;
import org.gusdb.wdk.service.formatter.ValidationFormatter;
import org.gusdb.wdk.service.request.exception.ConflictException;
import org.gusdb.wdk.service.request.exception.DataValidationException;
import org.gusdb.wdk.service.request.exception.RequestMisformatException;
Expand Down Expand Up @@ -91,10 +92,12 @@ public Response setUserProfile(String body)
throw new BadRequestException(e);
}
catch (InvalidPropertiesException e) {
throw new DataValidationException(e.getMessage());
// convert to use validation bundle JSON formatting
throw new DataValidationException(ValidationFormatter.getValidationBundleJson(e.getMessage()).toString());
}
catch (InvalidUsernameOrEmailException e) {
throw new ConflictException(e.getMessage());
// convert to use validation bundle JSON formatting
throw new ConflictException(ValidationFormatter.getValidationBundleJson(e.getMessage()).toString());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.gusdb.wdk.model.user.User;
import org.gusdb.wdk.model.user.UserPreferenceFactory;
import org.gusdb.wdk.model.user.UserPreferences;
import org.gusdb.wdk.service.formatter.ValidationFormatter;
import org.gusdb.wdk.service.request.exception.ConflictException;
import org.gusdb.wdk.service.request.exception.DataValidationException;
import org.gusdb.wdk.service.request.exception.RequestMisformatException;
Expand Down Expand Up @@ -77,11 +78,13 @@ public Response createNewUser(String body) throws RequestMisformatException, Dat
.location(getUriInfo().getAbsolutePathBuilder().build(newUser.getUserId()))
.build();
}
catch (InvalidUsernameOrEmailException e) {
throw new ConflictException(e.getMessage());
}
catch (InvalidPropertiesException e) {
throw new DataValidationException(e.getMessage());
// convert to use validation bundle JSON formatting
throw new DataValidationException(ValidationFormatter.getValidationBundleJson(e.getMessage()).toString());
}
catch (InvalidUsernameOrEmailException e) {
// convert to use validation bundle JSON formatting
throw new ConflictException(ValidationFormatter.getValidationBundleJson(e.getMessage()).toString());
}
catch (JSONException e) {
throw new RequestMisformatException(e.getMessage(), e);
Expand Down

0 comments on commit 4fc6683

Please sign in to comment.