markusthoemmes commented on a change in pull request #2218: Port Controller 
from Spray to Akka
URL: 
https://github.com/apache/incubator-openwhisk/pull/2218#discussion_r127040698
 
 

 ##########
 File path: common/scala/src/main/scala/whisk/http/BasicHttpService.scala
 ##########
 @@ -86,39 +94,58 @@ trait BasicHttpService extends HttpService with 
TransactionCounter {
      */
     def loglevelForRoute(route: String): Logging.LogLevel = Logging.InfoLevel
 
+    /** Rejection handler to terminate connection on a bad request. Delegates 
to Akka handler. */
+    val prioritizeRejections = recoverRejections { rejections =>
+        val priorityRejection = 
rejections.find(_.isInstanceOf[UnacceptedResponseContentTypeRejection]).getOrElse(null)
+
+        if (priorityRejection != null) {
+            Rejected(Seq(priorityRejection))
+        } else {
+            Rejected(rejections)
+        }
 
 Review comment:
   Idiomatically these would be:
   
   ```scala
   val priorityRejection = rejections.find { case _: 
UnacceptedResponseContentTypeRejection => true }
   priorityRejection.map(rejection => 
Rejected(Seq(rejection))).getOrElse(Rejected(rejections))
   ```
   
   `getOrElse(null)` should be avoided at any costs and is in fact not useful 
in this case. Alternatively you could've omitted that and called 
`priorityRejection.isDefined` on the option. Using map though is the safest way 
here.
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to