<commit_before>package com.devicehive.controller.exceptions;

import com.devicehive.controller.ResponseFactory;
import com.devicehive.model.ErrorResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.ws.rs.BadRequestException;
import javax.ws.rs.NotAllowedException;
import javax.ws.rs.NotFoundException;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;

/**
 * @author <NAME>
 * @since 30.07.13
 */
@Provider
public class AllExceptionMapper implements ExceptionMapper<Exception> {

    private static Logger logger = LoggerFactory.getLogger(AllExceptionMapper.class);

    @Override
    public Response toResponse(Exception exception) {
        logger.error("Error: ", exception);

        Response.Status responseCode = Response.Status.INTERNAL_SERVER_ERROR;
        String message = exception.getMessage();
        if (exception instanceof NotFoundException) {
            responseCode = Response.Status.NOT_FOUND;
            message = exception.getMessage();
        } else if (exception instanceof BadRequestException) {
            responseCode = Response.Status.BAD_REQUEST;
            message = exception.getMessage();
        } else if (exception instanceof NotAllowedException) {
            responseCode = Response.Status.METHOD_NOT_ALLOWED;
        }

        return ResponseFactory.response(responseCode, new ErrorResponse(message));
    }
}<commit_msg>web application exceptions fix<commit_after>package com.devicehive.controller.exceptions;

import com.devicehive.controller.ResponseFactory;
import com.devicehive.model.ErrorResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.ws.rs.BadRequestException;
import javax.ws.rs.NotAllowedException;
import javax.ws.rs.NotFoundException;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;

/**
 * @author <NAME>
 * @since 30.07.13
 */
@Provider
public class AllExceptionMapper implements ExceptionMapper<Exception> {

    private static Logger logger = LoggerFactory.getLogger(AllExceptionMapper.class);

    @Override
    public Response toResponse(Exception exception) {
        logger.error("Error: ", exception);

        Response.Status responseCode = Response.Status.INTERNAL_SERVER_ERROR;
        String message = exception.getMessage();
        if (exception instanceof NotFoundException) {
            responseCode = Response.Status.NOT_FOUND;
            message = exception.getMessage();
        } else if (exception instanceof BadRequestException) {
            responseCode = Response.Status.BAD_REQUEST;
            message = exception.getMessage();
        } else if (exception instanceof NotAllowedException) {
            responseCode = Response.Status.METHOD_NOT_ALLOWED;
        } else if (exception instanceof WebApplicationException){
            WebApplicationException realException = (WebApplicationException) exception;
            int response = realException.getResponse().getStatus();
            responseCode = Response.Status.fromStatusCode(response);
        }

        return ResponseFactory.response(responseCode, new ErrorResponse(responseCode.getStatusCode(), message));
    }
}
{'fraction_non_alphanumeric': 0.09187709157286279, 'fraction_numerical': 0.004867660480681472, 'mean_word_length': 3.8, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '422521', 'n_tokens_mistral': 843, 'n_tokens_neox': 837, 'n_words': 176}