You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@openwhisk.apache.org by GitBox <gi...@apache.org> on 2020/03/03 12:27:26 UTC

[GitHub] [openwhisk] rabbah commented on a change in pull request #4848: Remove explicit right biasing of Eithers.

rabbah commented on a change in pull request #4848: Remove explicit right biasing of Eithers.
URL: https://github.com/apache/openwhisk/pull/4848#discussion_r386986184
 
 

 ##########
 File path: common/scala/src/main/scala/org/apache/openwhisk/core/entity/Attachments.scala
 ##########
 @@ -66,13 +66,11 @@ object Attachments {
     implicit val serdes = {
       implicit val contentTypeSerdes = new RootJsonFormat[ContentType] {
         override def write(c: ContentType) = JsString(c.value)
-        override def read(js: JsValue) =
-          Try {
-            val JsString(c) = js
-            ContentType.parse(c).right.get
-          } getOrElse {
-            throw new DeserializationException("Could not deserialize content-type")
-          }
+        override def read(js: JsValue) = {
+          Try(js.convertTo[String])
+            .flatMap(ContentType.parse(_).fold(_ => Failure(new Exception("failed to parse content-type")), Success(_)))
 
 Review comment:
   could this be further simplified to map to success only? we're not using the exception from left.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services