<commit_before>package be.vlaanderen.awv

import be.vlaanderen.awv.atom.Marshallers.{JsonUnmarshaller, XmlUnmarshaller}

import scala.util.{Failure, Success, Try}

package object atom {

  type FeedProcessingResult = Try[Unit]

  type FeedEntryUnmarshaller[T] = (String) => Try[Feed[T]]

  trait FeedUnmarshaller[T] {

    def jsonUnmarshaller: JsonUnmarshaller[Feed[T]]
    def xmlUnmarshaller: XmlUnmarshaller[Feed[T]]

    def unmarshal(contentType: Option[String], body: String): Try[Feed[T]] = {
      try {
        contentType match {
          case Some(contentType) if contentType.startsWith("application/json") => Success(jsonUnmarshaller(body))
          case _ => Success(xmlUnmarshaller(body))
        }
      } catch {
        case e: Exception =>
          e.printStackTrace()
          //TODO log it
          Failure(new FeedProcessingException(None, s"problem unmarshalling feed : ${e.getMessage}"))
      }
    }

  }

}
<commit_msg>AT-9: Catch on NonFatal instead of Exception + we should not log the exception because it's being propagate (encapsulated in a Failure) + Using AnyJson extractor to increase clarity on pattern matching<commit_after>package be.vlaanderen.awv

import be.vlaanderen.awv.atom.Marshallers.{JsonUnmarshaller, XmlUnmarshaller}

import scala.util.control.NonFatal
import scala.util.{Failure, Success, Try}

package object atom {

  type FeedProcessingResult = Try[Unit]

  type FeedEntryUnmarshaller[T] = (String) => Try[Feed[T]]

  trait FeedUnmarshaller[T] {

    def jsonUnmarshaller: JsonUnmarshaller[Feed[T]]
    def xmlUnmarshaller: XmlUnmarshaller[Feed[T]]



    def unmarshal(contentType: Option[String], body: String): Try[Feed[T]] = {
      try {
        contentType match {
          case AnyJson(_) => Success(jsonUnmarshaller(body))
          case _ => Success(xmlUnmarshaller(body))
        }
      } catch {
        case NonFatal(e) =>
          Failure(new FeedProcessingException(None, s"problem unmarshalling feed : ${e.getMessage}"))
      }
    }

    object AnyJson {
      def unapply(contentTypeOpt: Some[String]): Option[String] =
        if (contentTypeOpt.get.startsWith("application/json"))
          contentTypeOpt
        else
          None
    }

  }

}

{'fraction_non_alphanumeric': 0.10767160161507403, 'fraction_numerical': 0.00044863167339614175, 'mean_word_length': 3.3385214007782102, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '831118', 'n_tokens_mistral': 692, 'n_tokens_neox': 695, 'n_words': 149}