Permalink
Browse files

Fixed bug in communication error logging when the error message is null

Better error handling for generation of communication message JSON
  • Loading branch information...
darkfrog26 committed Feb 8, 2019
1 parent af353ac commit b491aebb01001d0bc05b7eb906b22ed0dac5a687
@@ -3,7 +3,7 @@ import sbtcrossproject.CrossPlugin.autoImport.crossProject

name := "youi"
organization in ThisBuild := "io.youi"
version in ThisBuild := "0.10.4"
version in ThisBuild := "0.10.5-SNAPSHOT"
scalaVersion in ThisBuild := "2.12.8"
crossScalaVersions in ThisBuild := List("2.12.8", "2.11.12")
resolvers in ThisBuild += Resolver.sonatypeRepo("releases")
@@ -97,7 +97,8 @@ class CommunicationInternal private[communication](communication: Communication)
endPoint(message).map { content =>
send := CommunicationMessage(CommunicationMessage.MethodResponse, message.endPoint, message.invocationId, List(content), None)
}.failed.foreach { t =>
send := CommunicationMessage(CommunicationMessage.MethodResponse, message.endPoint, message.invocationId, Nil, Some(t.getMessage))
val error = Option(t.getMessage).orElse(Some("An error occurred"))
send := CommunicationMessage(CommunicationMessage.MethodResponse, message.endPoint, message.invocationId, Nil, error)
communication.error(t)
}
}
@@ -7,9 +7,11 @@ case class CommunicationMessage(messageType: Int,
invocationId: Int,
content: List[String],
error: Option[String]) {
lazy val parsableString: String = {
lazy val parsableString: String = try {
val json = JsonUtil.toJsonString(this)
s"|CM|$json"
} catch {
case t: Throwable => throw new RuntimeException(s"Unable to convert $this to JSON", t)
}
}

0 comments on commit b491aeb

Please sign in to comment.