<commit_before>/**
 * Copyright (c) 2013-2016, The SeedStack authors <http://seedstack.org>
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */
package org.seedstack.seed.web.internal.diagnostic;

import org.seedstack.seed.diagnostic.DiagnosticManager;
import org.seedstack.seed.SeedException;
import org.seedstack.seed.web.internal.ServletContextUtils;
import org.seedstack.seed.web.internal.WebErrorCode;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import java.io.IOException;

public class WebDiagnosticFilter implements Filter {
    private DiagnosticManager diagnosticManager;

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        diagnosticManager = ServletContextUtils.getInjector(filterConfig.getServletContext()).getInstance(DiagnosticManager.class);
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        try {
            chain.doFilter(request, response);
        } catch (SeedException e) {
            diagnosticManager.dumpDiagnosticReport(e);
            throw e;
        } catch (Exception e) {
            diagnosticManager.dumpDiagnosticReport(e);
            throw SeedException.wrap(e, WebErrorCode.UNEXPECTED_EXCEPTION);
        }
    }

    @Override
    public void destroy() {
        // nothing to do here
    }
}<commit_msg>Translate exceptions in web request diagnostic<commit_after>/**
 * Copyright (c) 2013-2016, The SeedStack authors <http://seedstack.org>
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */
package org.seedstack.seed.web.internal.diagnostic;

import org.seedstack.seed.core.Seed;
import org.seedstack.seed.diagnostic.DiagnosticManager;
import org.seedstack.seed.web.internal.ServletContextUtils;
import org.seedstack.shed.exception.BaseException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import java.io.IOException;

public class WebDiagnosticFilter implements Filter {
    private DiagnosticManager diagnosticManager;

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        diagnosticManager = ServletContextUtils.getInjector(filterConfig.getServletContext()).getInstance(DiagnosticManager.class);
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        try {
            chain.doFilter(request, response);
        } catch (Exception e) {
            BaseException translated = Seed.translateException(e);
            diagnosticManager.dumpDiagnosticReport(translated);
            throw translated;
        }
    }

    @Override
    public void destroy() {
        // nothing to do here
    }
}
{'fraction_non_alphanumeric': 0.08561341571050309, 'fraction_numerical': 0.00706090026478376, 'mean_word_length': 3.809052333804809, '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': '3441309', 'n_tokens_mistral': 911, 'n_tokens_neox': 883, 'n_words': 239}