<commit_before>package uk.gov.register.providers;

import org.glassfish.jersey.server.ParamException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import uk.gov.register.views.ViewFactory;
import uk.gov.register.views.representations.ExtraMediaType;

import javax.inject.Inject;
import javax.ws.rs.ClientErrorException;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;

@Provider
public class ThrowableExceptionMapper implements ExceptionMapper<Throwable> {

    public static final Logger LOGGER = LoggerFactory.getLogger(ThrowableExceptionMapper.class);

    private ViewFactory viewFactory;

    @Inject
    public ThrowableExceptionMapper(ViewFactory viewFactory) {
        this.viewFactory = viewFactory;
    }

    @Override
    public Response toResponse(Throwable exception) {
        if (exception instanceof ClientErrorException) {
            throw (ClientErrorException) exception;
        }

        if (exception instanceof ParamException.PathParamException) {
            return Response.status(Response.Status.NOT_FOUND)
                    .header(HttpHeaders.CONTENT_TYPE, ExtraMediaType.TEXT_HTML)
                    .entity(viewFactory.thymeleafView("404.html"))
                    .build();        }

        LOGGER.warn("Uncaught exception: {}", exception);

        return Response.status(Response.Status.INTERNAL_SERVER_ERROR)<commit_msg>Log Internal Server Errors as errors<commit_after>package uk.gov.register.providers;

import org.glassfish.jersey.server.ParamException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import uk.gov.register.views.ViewFactory;
import uk.gov.register.views.representations.ExtraMediaType;

import javax.inject.Inject;
import javax.ws.rs.ClientErrorException;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;

@Provider
public class ThrowableExceptionMapper implements ExceptionMapper<Throwable> {

    public static final Logger LOGGER = LoggerFactory.getLogger(ThrowableExceptionMapper.class);

    private ViewFactory viewFactory;

    @Inject
    public ThrowableExceptionMapper(ViewFactory viewFactory) {
        this.viewFactory = viewFactory;
    }

    @Override
    public Response toResponse(Throwable exception) {
        if (exception instanceof ClientErrorException) {
            throw (ClientErrorException) exception;
        }

        if (exception instanceof ParamException.PathParamException) {
            return Response.status(Response.Status.NOT_FOUND)
                    .header(HttpHeaders.CONTENT_TYPE, ExtraMediaType.TEXT_HTML)
                    .entity(viewFactory.thymeleafView("404.html"))
                    .build();        }

        LOGGER.error("Uncaught exception: {}", exception);

        return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
{'fraction_non_alphanumeric': 0.08766014834794336, 'fraction_numerical': 0.0033715441672285905, 'mean_word_length': 3.621495327102804, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '2770488', 'n_tokens_mistral': 807, 'n_tokens_neox': 791, 'n_words': 148}