package au.com.billon.stt.exception;

import org.skife.jdbi.v2.exceptions.DBIException;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;

/**
 * Created by Trevor Li on 7/4/15.
 */
@Provider
public class DBIExceptionMapper implements ExceptionMapper<DBIException> {

    public Response toResponse(DBIException exception) {
        if (exception.getMessage().indexOf("Unique index or primary key violation") > -1) {
            return Response.status(Response.Status.CONFLICT).type("text/plain").entity("The name is already taken").build();
        }
        return Response.status(Response.Status.BAD_REQUEST).type("text/plain").entity("The request is not valid").build();
    }

}

@@ -31,16 +31,76 @@
 ption;%0A%0A
+import io.dropwizard.jdbi.jersey.LoggingDBIExceptionMapper;%0A
 import o
@@ -179,48 +179,8 @@
 se;%0A
-import javax.ws.rs.ext.ExceptionMapper;%0A
 impo
@@ -298,19 +298,26 @@
 per 
-implement
+extend
 s 
+LoggingDBI
 Exce
@@ -331,25 +331,25 @@
 pper
-%3CDBIException%3E %7B%0A
+ %7B%0A%0A    @Override
 %0A   

optimise to make it universal