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:39:54 UTC

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

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

 ##########
 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:
   Left doesn't have an exception but a custom error class. To fold everything into a Try, the left needs to be filled with an Exception or we'd need to throw in two places alternatively.

----------------------------------------------------------------
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