<commit_before>'use strict'

const MapErrorCodeToView = {
  404: 'frontend.404',
};

/**
 * This class handles all exceptions thrown during
 * the HTTP request lifecycle.
 *
 * @class ExceptionHandler
 */
class ExceptionHandler {
  _getYouchError (error, req, isJSON) {
    const Youch = require('youch');
    const youch = new Youch(error, req);
    if (isJSON) {
      return youch.toJSON();
    }
    return youch.toHTML();
  }

  /**
   * Handle exception thrown during the HTTP lifecycle
   *
   * @method handle
   *
   * @param  {Object} error
   * @param  {Object} options.request
   * @param  {Object} options.response
   *
   * @return {void}
   */
  async handle (error, { request, response, view }) {
    //if (process.env.NODE_ENV === 'development') {
      const isJSON = request.accepts(['html', 'json']) === 'json';
      const formattedError = await this._getYouchError(error, request.request, isJSON);
      response
        .status(error.status)
        .send(formattedError);
      return;
    //}

    response
      .status(error.status)
      .send(view.render('frontend.error', { error: error }));
  }

  /**
   * Report exception for logging or debugging.
   *
   * @method report
   *
   * @param  {Object} error
   * @param  {Object} options.request
   *
   * @return {void}
   */<commit_msg>Fix handler. Found the issue.<commit_after>'use strict'

const MapErrorCodeToView = {
  404: 'frontend.404',
};

/**
 * This class handles all exceptions thrown during
 * the HTTP request lifecycle.
 *
 * @class ExceptionHandler
 */
class ExceptionHandler {
  _getYouchError (error, req, isJSON) {
    const Youch = require('youch');
    const youch = new Youch(error, req);
    if (isJSON) {
      return youch.toJSON();
    }
    return youch.toHTML();
  }

  /**
   * Handle exception thrown during the HTTP lifecycle
   *
   * @method handle
   *
   * @param  {Object} error
   * @param  {Object} options.request
   * @param  {Object} options.response
   *
   * @return {void}
   */
  async handle (error, { request, response, view }) {
    if (process.env.NODE_ENV === 'development') {
      const isJSON = request.accepts(['html', 'json']) === 'json';
      const formattedError = await this._getYouchError(error, request.request, isJSON);
      response
        .status(error.status)
        .send(formattedError);
      return;
    }

    response
      .status(error.status)
      .send(view.render('frontend.error', { error: error }));
  }

  /**
   * Report exception for logging or debugging.
   *
   * @method report
   *
   * @param  {Object} error
   * @param  {Object} options.request
   *
   * @return {void}
   */
{'fraction_non_alphanumeric': 0.13886792452830188, 'fraction_numerical': 0.004528301886792453, 'mean_word_length': 2.676837725381415, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4118199', 'n_tokens_mistral': 850, 'n_tokens_neox': 833, 'n_words': 212}