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 2019/03/06 15:16:05 UTC

[GitHub] [incubator-openwhisk-runtime-nodejs] mrutkows edited a comment on issue #113: Fix Node Express 'use()' method by removing invalid 'err' parameter

mrutkows edited a comment on issue #113: Fix Node Express 'use()' method by removing invalid 'err' parameter
URL: https://github.com/apache/incubator-openwhisk-runtime-nodejs/pull/113#issuecomment-470145368
 
 
   SO... I have put back the default error handler which will only be invoked when invalid JSON is received by any of the endpoints (i.e., handle a JSON parser error) despite the fact that the default NodeJS handler catches it and properly returns ```Response code: 400 (Bad Request)```.
   
   Why?
   1) because the default handler passes back HTML in the body of the request, for example:
   ```
   <!DOCTYPE html>
   <html lang="en">
   <head>
       <meta charset="utf-8">
       <title>Error</title>
   </head>
   <body>
   <pre>SyntaxError: Unexpected token } in JSON at position 161 ...</pre>
   </body>
   </html>
   ```
   
   Leaving our own handler, in retrospect, actually allows us to consistently use a status code (500) we choose, as well as return JSON in the body of the response.
   
   2) Acknowledging that receiving BAD JSON is unlikely when running under the OpenWhisk platform (Controller/Invoker); however, as we move to run under other platforms like Knative where other services may be hitting our runtimes directly (no controller) this edge case becomes much more likely.
   
   ---
   BUT, I also added another use() method that actually short-circuits any requests received by NodeJS express that attempt to access routes which we have no registered handlers for.
   
   This too is desirable going forward as we run on other platforms since we will both be registering different routes/handlers and allowing other services (or some other control plane) to hit our runtime at these different endpoints.  If indeed, we allow variant builds of our runtimes, it may become more likely situations arise where invalid routes (mismatch bw/ control plane and runtime) may occur.

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