SHARE
TWEET

Untitled

a guest Oct 21st, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. object ServingError{
  2. // we are adding a method modification content method, to be used by the modification traits  def modifyContent(error: ServingError, content: String): ServingError = {
  3.    error match {
  4.      case f: FatalError => FatalError(exceptionCause = f.exceptionCause, content = content)
  5.      case i: InvalidRequestError => InvalidRequestError(i.paramName, i.paramValue, content = content)
  6.    }
  7.  }
  8. }
  9.  
  10. trait JsonTransformer extends Sender {
  11.  import ServingError._
  12.  abstract override def send(event: ServingError): Unit = {
  13.    super.send(modifyContent(event, {
  14.      val date = event match {
  15.        case d: DateTimestampedMessage => "\"date\":" + d.date
  16.        case _ => ""
  17.      }
  18.      val cause = event match {
  19.        case f: FatalError => "\"cause\":" + f.exceptionCause
  20.        case i: InvalidRequestError => "\"cause\":" + i.paramName +":" +i.paramValue
  21.      }
  22.      s""" { "code:"${event.code}, $date $cause } """
  23.    }))
  24.  }
  25. }
  26. trait CsVTransformer extends Sender {
  27.  import ServingError._
  28.  abstract override def send(event: ServingError): Unit = {
  29.    super.send(modifyContent(event, {
  30.      val date = event match {
  31.        case d: DateTimestampedMessage => d.date
  32.        case _ => ""
  33.      }
  34.      val cause = event match {
  35.        case f: FatalError => f.exceptionCause
  36.        case i: InvalidRequestError => i.paramName +"," +i.paramValue
  37.      }
  38.      s"""${event.code},$date$cause"""
  39.    }))
  40.  }
  41. }
  42.  
  43. trait Timestamp {
  44.  val date: Date = new Date()
  45. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top