Skip to main content
added 12 characters in body
Source Link

Javax has a interface name as ExceptionMapper. Please refer the below code snippet, For every RuntimeException in your application it will map it to a Json Response entity.

public class ExceptionMapper implements ExceptionMapper {

public class RuntimeExceptionMapper implements ExceptionMapper <RuntimeException> { @Override public Response toResponse(RuntimeException exception) { ErrorResponse errorResponse = new ErrorResponse(); errorResponse.setMessage(exception.getMessage); if (exception== null) { logger.error("Exception Details Not found"); } else { return Response.status(Status.INTERNAL_SERVER_ERROR) .entity(errorResponse ) .type(MediaType.APPLICATION_JSON) .header("trace-id", "1234").build(); } } 

}

Javax has a interface name as ExceptionMapper. Please refer the below code snippet, For every RuntimeException in your application it will map it to a Json Response entity.

public class ExceptionMapper implements ExceptionMapper {

@Override public Response toResponse(RuntimeException exception) { ErrorResponse errorResponse = new ErrorResponse(); errorResponse.setMessage(exception.getMessage); if (exception== null) { logger.error("Exception Details Not found"); } else { return Response.status(Status.INTERNAL_SERVER_ERROR) .entity(errorResponse ) .type(MediaType.APPLICATION_JSON) .header("trace-id", "1234").build(); } } 

}

Javax has a interface name as ExceptionMapper. Please refer the below code snippet, For every RuntimeException in your application it will map it to a Json Response entity.

public class RuntimeExceptionMapper implements ExceptionMapper <RuntimeException> { @Override public Response toResponse(RuntimeException exception) { ErrorResponse errorResponse = new ErrorResponse(); errorResponse.setMessage(exception.getMessage); if (exception== null) { logger.error("Exception Details Not found"); } else { return Response.status(Status.INTERNAL_SERVER_ERROR) .entity(errorResponse ) .type(MediaType.APPLICATION_JSON) .header("trace-id", "1234").build(); } } 

}

Source Link

Javax has a interface name as ExceptionMapper. Please refer the below code snippet, For every RuntimeException in your application it will map it to a Json Response entity.

public class ExceptionMapper implements ExceptionMapper {

@Override public Response toResponse(RuntimeException exception) { ErrorResponse errorResponse = new ErrorResponse(); errorResponse.setMessage(exception.getMessage); if (exception== null) { logger.error("Exception Details Not found"); } else { return Response.status(Status.INTERNAL_SERVER_ERROR) .entity(errorResponse ) .type(MediaType.APPLICATION_JSON) .header("trace-id", "1234").build(); } } 

}