<commit_before>package uk.gov.gds.router.controller

import uk.gov.gds.router.util.Logging
import util.DynamicVariable
import org.scalatra.ScalatraFilter
import java.net.SocketTimeoutException

abstract class ControllerBase extends ScalatraFilter with Logging {

  private val threadRequestInfo = new DynamicVariable[RequestInfo](null)

  after() {
    threadRequestInfo.value_=(null)
  }

  error {
    case s: SocketTimeoutException => errorDocument(504)
    case e: Exception => errorDocument(500)
  }

  protected def halt(statusCode: Int) {
    super.halt(status = statusCode, body = errorDocument(statusCode), headers = Map("Content-Type" -> "text/html"))
  }

  def errorDocument(code: Int) = {
    logger.error("Serving error document with status {}", code)
    response.setHeader("Content-Type", "text/html")<commit_msg>Fall back to jetty for simple exception cases<commit_after>package uk.gov.gds.router.controller

import uk.gov.gds.router.util.Logging
import util.DynamicVariable
import org.scalatra.ScalatraFilter
import java.net.SocketTimeoutException

abstract class ControllerBase extends ScalatraFilter with Logging {

  private val threadRequestInfo = new DynamicVariable[RequestInfo](null)

  after() {
    threadRequestInfo.value_=(null)
  }

  error {
    case s: SocketTimeoutException => errorDocument(504)
  }

  protected def halt(statusCode: Int) {
    super.halt(status = statusCode, body = errorDocument(statusCode), headers = Map("Content-Type" -> "text/html"))
  }

  def errorDocument(code: Int) = {
    logger.error("Serving error document with status {}", code)
    response.setHeader("Content-Type", "text/html")
{'fraction_non_alphanumeric': 0.10753341433778858, 'fraction_numerical': 0.0054678007290400975, 'mean_word_length': 4.8612099644128115, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, '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': '2371773', 'n_tokens_mistral': 485, 'n_tokens_neox': 468, 'n_words': 112}