<commit_before>package com.backend.rest.jersey;

import com.backend.guice.validation.ValidationException;
import com.backend.util.Constants;
import com.google.common.collect.Maps;
import com.sun.jersey.api.NotFoundException;
import io.fnx.backend.manager.UniqueViolationException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.validation.ConstraintViolation;
import javax.ws.rs.core.Response;

import java.util.*;

import static java.lang.String.format;

/**
 * Handles Exception rendering for Jersey
 */
public class ExceptionMapper implements javax.ws.rs.ext.ExceptionMapper<Throwable> {

    private static final Logger log = LoggerFactory.getLogger(ExceptionMapper.class);

    @Override
    public Response toResponse(Throwable t) {
        if (t instanceof NotFoundException) {
            final NotFoundException nfe = (NotFoundException) t;
            log.debug(format("URI Not-Found: %s", nfe.getNotFoundUri()));
            return Response.status(Response.Status.NOT_FOUND).build();
        } else if (t instanceof ValidationException) {
            final ErrorResponse err = renderValidationError((ValidationException) t);
            return unprocessableEntity(err);
        } else if (t instanceof UniqueViolationException) {
            return unprocessableEntity(renderUniqueViolationException((UniqueViolationException) t));
        } else if (t instanceof com.backend.service.NotFoundException) {
            return unprocessableEntity(entityNotFound((com.backend.service.NotFoundException) t));
        } else {
            log.warn(t.getMessage(), t);
            return Response.status(500).entity(t.getMessage()).build();<commit_msg>MOD Respond with status 403 Forbidden when PermissionDeniedException occured<commit_after>package com.backend.rest.jersey;

import com.backend.guice.validation.ValidationException;
import com.backend.util.Constants;
import com.google.common.collect.Maps;
import com.sun.jersey.api.NotFoundException;
import io.fnx.backend.manager.UniqueViolationException;
import io.fnx.backend.tools.authorization.PermissionDeniedException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.validation.ConstraintViolation;
import javax.ws.rs.core.Response;

import java.util.*;

import static java.lang.String.format;

/**
 * Handles Exception rendering for Jersey
 */
public class ExceptionMapper implements javax.ws.rs.ext.ExceptionMapper<Throwable> {

    private static final Logger log = LoggerFactory.getLogger(ExceptionMapper.class);

    @Override
    public Response toResponse(Throwable t) {
        if (t instanceof NotFoundException) {
            final NotFoundException nfe = (NotFoundException) t;
            log.debug(format("URI Not-Found: %s", nfe.getNotFoundUri()));
            return Response.status(Response.Status.NOT_FOUND).build();
        } else if (t instanceof ValidationException) {
            final ErrorResponse err = renderValidationError((ValidationException) t);
            return unprocessableEntity(err);
        } else if (t instanceof UniqueViolationException) {
            return unprocessableEntity(renderUniqueViolationException((UniqueViolationException) t));
        } else if (t instanceof com.backend.service.NotFoundException) {
            return unprocessableEntity(entityNotFound((com.backend.service.NotFoundException) t));
        } else if (t instanceof PermissionDeniedException) {
            return Response.status(Response.Status.FORBIDDEN).
                    entity(new ErrorResponse("PermissionDenied", t.getMessage(), null)).
                    build();
        } else {
            log.warn(t.getMessage(), t);
            return Response.status(500).entity(t.getMessage()).build();
{'fraction_non_alphanumeric': 0.09989287627209427, 'fraction_numerical': 0.0034815211569362613, 'mean_word_length': 3.7762148337595907, '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': '6720344', 'n_tokens_mistral': 974, 'n_tokens_neox': 968, 'n_words': 209}