<commit_before>/*
 * Telefónica Digital - Product Development and Innovation
 *
 * THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
 * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
 *
 * Copyright (c) Telefónica Investigación y Desarrollo S.A.U.
 * All rights reserved.
 */

package es.tid.cosmos.api.controllers

import play.api.Play
import play.api.Play.current
import play.api.libs.json._

package object common {
  /**
   * Formats an internal server exception to JSON.
   * Stack traces are not shown in production mode.
   *
   * @param message One line explanation
   * @param ex      Cause of the internal error
   * @return        Error description
   */
  def formatInternalException(message: String, ex: Throwable): JsValue = {
    val basicMessage = Map("error" -> "%s: %s".format(message, ex.getMessage))
    val errorMessage =
      if (Play.isProd) basicMessage
      else basicMessage ++ Map("exception" -> ex.getClass.getCanonicalName,
                               "stack_trace" -> ex.getStackTraceString)
    Json.toJson(errorMessage)
  }
}<commit_msg>Replace string formatting by interpolation<commit_after>/*
 * Telefónica Digital - Product Development and Innovation
 *
 * THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
 * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
 *
 * Copyright (c) Telefónica Investigación y Desarrollo S.A.U.
 * All rights reserved.
 */

package es.tid.cosmos.api.controllers

import play.api.Play
import play.api.Play.current
import play.api.libs.json._

package object common {
  /**
   * Formats an internal server exception to JSON.
   * Stack traces are not shown in production mode.
   *
   * @param message One line explanation
   * @param ex      Cause of the internal error
   * @return        Error description
   */
  def formatInternalException(message: String, ex: Throwable): JsValue = {
    val basicMessage = Map("error" -> s"${message}: ${ex.getMessage}")
    val errorMessage =
      if (Play.isProd) basicMessage
      else basicMessage ++ Map("exception" -> ex.getClass.getCanonicalName,
                               "stack_trace" -> ex.getStackTraceString)
    Json.toJson(errorMessage)
  }
}
{'fraction_non_alphanumeric': 0.08936698386429458, 'fraction_numerical': 0.0, 'mean_word_length': 3.2198952879581153, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1087998', 'n_tokens_mistral': 675, 'n_tokens_neox': 660, 'n_words': 233}