You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2019/07/26 11:46:32 UTC

[sling-whiteboard] 01/02: Content-type fix, star resource type, 500 status code

This is an automated email from the ASF dual-hosted git repository.

bdelacretaz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-whiteboard.git

commit 1684a6c9bc6941702a555286dbd8b91bedd85ff5
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Fri Jul 26 13:46:02 2019 +0200

    Content-type fix, star resource type, 500 status code
---
 serverless-microsling/lib/openwhisk-renderer.js | 4 +++-
 serverless-microsling/lib/render.js             | 4 ++--
 serverless-microsling/microsling.js             | 6 +++---
 3 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/serverless-microsling/lib/openwhisk-renderer.js b/serverless-microsling/lib/openwhisk-renderer.js
index 5ac5259..d703607 100644
--- a/serverless-microsling/lib/openwhisk-renderer.js
+++ b/serverless-microsling/lib/openwhisk-renderer.js
@@ -31,7 +31,9 @@ const getActionInfo = async (resourceType, extension) => {
     ow.actions.list()
     .then(actions => {
       const act = actions.find(act => {
-        return resourceType == getAnnotation(act, 'sling:resourceType') && extension == getAnnotation(act, 'sling:extensions')
+        const rtAnnotation = getAnnotation(act, 'sling:resourceType');
+        return ('*' == rtAnnotation || resourceType ==  rtAnnotation)
+          && extension == getAnnotation(act, 'sling:extensions');
       })
       let result;
       if(act) {
diff --git a/serverless-microsling/lib/render.js b/serverless-microsling/lib/render.js
index 91fcaf9..6d4bca0 100644
--- a/serverless-microsling/lib/render.js
+++ b/serverless-microsling/lib/render.js
@@ -55,7 +55,7 @@ async function render(context) {
   }
   const rendererInfo = await selectRendererInfo(resourceType, extension);
   if(context.debug) {
-    console.log(rendererInfo);
+    console.log(`rendererInfo: ${JSON.stringify(rendererInfo, 2, null)}`);
   }
   if(!rendererInfo) {
     throw Error(`Renderer not found for ${resourceType} extension ${extension}`);
@@ -66,7 +66,7 @@ async function render(context) {
   }
   context.response.body = rendered.output;
   context.response.headers = {
-    'Content-Type': rendererInfo.contentType
+    'Content-Type': rendererInfo.info.contentType
   };
 
   return context;
diff --git a/serverless-microsling/microsling.js b/serverless-microsling/microsling.js
index c9de1b9..629cf38 100644
--- a/serverless-microsling/microsling.js
+++ b/serverless-microsling/microsling.js
@@ -29,7 +29,7 @@ function main (params) {
     debug: params.debug
   };
 
-  return new Promise(function (resolvePromise) {
+  return new Promise(function (resolvePromise, reject) {
     if(context.debug) console.log(`start: ${JSON.stringify(context, 2, null)}`);
     resolveContent(context)
     .then(context => {
@@ -42,9 +42,9 @@ function main (params) {
     })
     .catch(e => {
       if(e.httpStatus) {
-        return resolvePromise({ status: e.httpStatus, body: e.message});
+        return resolvePromise({ statusCode: e.httpStatus, body: e.message});
       } else {
-        throw e;
+        return resolvePromise({ statusCode: 500, body: `${e.stack}\n`});
       }
     })
   })