<commit_before>package massivedecks.controllers

import java.net.URLEncoder
import java.nio.charset.StandardCharsets
import javax.inject.{Inject, Singleton}

import scala.concurrent.Future

import play.api.http.ContentTypes._
import play.api.http.HttpErrorHandler
import play.api.mvc.Results._
import play.api.mvc._
import play.api.Logger
import massivedecks.Config

@Singleton
class ErrorHandler @Inject()(getConfig: Config.Factory) extends HttpErrorHandler {
}<commit_msg>STAAAHP<commit_after>package massivedecks.controllers

import java.net.URLEncoder
import java.nio.charset.StandardCharsets
import javax.inject.{Inject, Singleton}

import scala.concurrent.Future

import play.api.http.ContentTypes._
import play.api.http.HttpErrorHandler
import play.api.mvc.Results._
import play.api.mvc._
import play.api.Logger
import massivedecks.Config

@Singleton
class ErrorHandler @Inject()(getConfig: Config.Factory) extends HttpErrorHandler {

  def onClientError(request: RequestHeader, statusCode: Int, rawMessage: String) = Future.successful {
    val config = getConfig(request)
    val (message, description) = statusCode match {
      case 400 => ("Bad Request", "there was a problem with the request you made")
      case 403 => ("Forbidden", ",you are not able to access the resource you requested")
      case 404 => ("Not Found", "the page you tried to access doesn't seem to exist")
      case _ => ("Client Error", "there was a problem with the request you made")
    }
    NotFound(views.html.error(
      config.url, config.version, statusCode, message, description,
        bugReportBody(config, request.path, s"$statusCode", rawMessage))).as(HTML)
  }

  def onServerError(request: RequestHeader, exception: Throwable): Future[Result] = Future.successful {
    val config = getConfig(request)
    val description = "the server had a problem trying to handle your request"
    Logger.error(exception.getMessage)
    NotFound(views.html.error(
      config.url, config.version, 500, "Server Error", description,
        bugReportBody(config, request.path, exception.getClass.getSimpleName, exception.getMessage))).as(HTML)
  }

  def bugReportBody(config: Config, path: String, error: String, detail: String) = {
    val extra = if (detail == null || detail.isEmpty) "" else s"\n\nDetail:\n\t${detail.take(1000)}"
    val v = config.version
    val version = if (v.isEmpty) "Not Specified" else v
    val text =
      (s"I was [a short explanation of what you were doing] when I got sent to '$path' and got a '$error' error.$extra"
       ++ s"\n\nApplication Info:\n\tVersion: $version\n\tURL: ${config.url}")
    URLEncoder.encode(text, StandardCharsets.UTF_8.name())
  }

}
{'fraction_non_alphanumeric': 0.11235119047619048, 'fraction_numerical': 0.006324404761904762, 'mean_word_length': 4.432323232323232, 'pattern_counts': {'":': 0, '<': 3, '<?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': '2227729', 'n_tokens_mistral': 811, 'n_tokens_neox': 794, 'n_words': 229}