package com.github.sbugat.samplerest.resource;

import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;

import com.github.sbugat.samplerest.exception.ApiException;
import com.github.sbugat.samplerest.exception.BadRequestException;
import com.github.sbugat.samplerest.exception.NotFoundException;
import com.github.sbugat.samplerest.model.ApiResponse;

@Provider
public class SampleExceptionMapper implements ExceptionMapper<Exception> {

	@Override
	public Response toResponse(final Exception exception) {
		if (exception instanceof javax.ws.rs.WebApplicationException) {
			final javax.ws.rs.WebApplicationException e = (javax.ws.rs.WebApplicationException) exception;
			return Response.status(e.getResponse().getStatus()).entity(new ApiResponse(e.getResponse().getStatus(), exception.getMessage())).type("application/json").build();
		} else if (exception instanceof com.fasterxml.jackson.core.JsonParseException) {
			return Response.status(Status.BAD_REQUEST).entity(new ApiResponse(400, "bad input")).build();
		} else if (exception instanceof NotFoundException) {
			return Response.status(Status.NOT_FOUND).entity(new ApiResponse(ApiResponse.ERROR, exception.getMessage())).type("application/json").build();
		} else if (exception instanceof BadRequestException) {
			return Response.status(Status.BAD_REQUEST).entity(new ApiResponse(ApiResponse.ERROR, exception.getMessage())).type("application/json").build();
		} else if (exception instanceof ApiException) {
			return Response.status(Status.BAD_REQUEST).entity(new ApiResponse(ApiResponse.ERROR, exception.getMessage())).type("application/json").build();
		} else {
			return Response.status(Status.INTERNAL_SERVER_ERROR).entity(new ApiResponse(500, "Internal server error")).type("application/json").build();
		}
	}
}
@@ -190,16 +190,79 @@
 vider;%0A%0A
+import org.slf4j.Logger;%0Aimport org.slf4j.ext.XLoggerFactory;%0A%0A
 import c
@@ -587,16 +587,111 @@
 ion%3E %7B%0A%0A
+%09private static final Logger logger = XLoggerFactory.getXLogger(SampleExceptionMapper.class);%0A%0A
 %09@Overri
@@ -1872,16 +1872,69 @@
  else %7B%0A
+%09%09%09logger.error(%22Internal server error%22, exception);%0A
 %09%09%09retur

Add exception mapper logger