Skip to content

Commit

Permalink
Remove usage of dropwizard-util's Strings from dropwizard-hibernate
Browse files Browse the repository at this point in the history
  • Loading branch information
rhowe committed Oct 17, 2021
1 parent 004ba6c commit 2509c37
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
@@ -1,19 +1,19 @@
package io.dropwizard.hibernate;

import io.dropwizard.jersey.errors.ErrorMessage;
import io.dropwizard.util.Strings;
import org.hibernate.exception.DataException;

import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
import java.util.Optional;

@Provider
public class DataExceptionMapper implements ExceptionMapper<DataException> {

@Override
public Response toResponse(DataException e) {
final String causeMessage = Strings.nullToEmpty(e.getCause().getMessage());
final String causeMessage = Optional.ofNullable(e.getCause().getMessage()).orElse("");
final String message = causeMessage.contains("EMAIL") ? "Wrong email" : "Wrong input";

return Response.status(Response.Status.BAD_REQUEST)
Expand Down
Expand Up @@ -12,7 +12,6 @@
import io.dropwizard.testing.ResourceHelpers;
import io.dropwizard.testing.junit5.DropwizardAppExtension;
import io.dropwizard.testing.junit5.DropwizardExtensionsSupport;
import io.dropwizard.util.Strings;
import org.hibernate.FlushMode;
import org.hibernate.HibernateException;
import org.hibernate.Session;
Expand Down Expand Up @@ -187,7 +186,7 @@ public static class ConstraintViolationExceptionMapper implements ExceptionMappe
@Override
public Response toResponse(ConstraintViolationException e) {
return Response.status(Response.Status.BAD_REQUEST)
.entity(new ErrorMessage(Response.Status.BAD_REQUEST.getStatusCode(), Strings.nullToEmpty(e.getCause().getMessage())))
.entity(new ErrorMessage(Response.Status.BAD_REQUEST.getStatusCode(), Optional.ofNullable(e.getCause().getMessage()).orElse("")))
.build();
}
}
Expand Down

0 comments on commit 2509c37

Please sign in to comment.