openwhisk-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From berst...@apache.org
Subject [incubator-openwhisk-package-kafka] branch master updated: Return Requested Accept Type (#199)
Date Tue, 15 Aug 2017 14:44:18 GMT
This is an automated email from the ASF dual-hosted git repository.

berstler pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk-package-kafka.git


The following commit(s) were added to refs/heads/master by this push:
     new 8f496f5  Return Requested Accept Type (#199)
8f496f5 is described below

commit 8f496f5a2fdbaec0251b50d1539913866767f597
Author: James Dubee <jwdubee@us.ibm.com>
AuthorDate: Tue Aug 15 10:44:16 2017 -0400

    Return Requested Accept Type (#199)
    
    * Return Requested Content Type
    * Ensure Proper Content-Type is Returned for all Web Action Responses
---
 action/kafkaFeedWeb.js      | 28 +++++++++++-----------------
 action/lib/common.js        | 11 +++++++++++
 action/messageHubFeedWeb.js | 28 +++++++++++-----------------
 3 files changed, 33 insertions(+), 34 deletions(-)

diff --git a/action/kafkaFeedWeb.js b/action/kafkaFeedWeb.js
index 256d908..7a57eb2 100644
--- a/action/kafkaFeedWeb.js
+++ b/action/kafkaFeedWeb.js
@@ -35,11 +35,7 @@ function main(params) {
                 .then(() => db.recordTrigger(validatedParams))
                 .then(() => {
                     console.log('successfully wrote the trigger');
-                    resolve({
-                        statusCode: 200,
-                        headers: {'Content-Type': 'text/plain'},
-                        body: validatedParams.uuid
-                    });
+                    resolve(common.webResponse(200, validatedParams.uuid));
                 })
                 .catch(error => {
                     console.log(`Failed to write the trigger ${error}`);
@@ -56,11 +52,7 @@ function main(params) {
                         body = error.authError;
                     }
 
-                    resolve({
-                        statusCode: statusCode,
-                        headers: {'Content-Type': 'text/plain'},
-                        body: body
-                    });
+                    resolve(common.webResponse(statusCode, body));
                 });
         } else if (params.__ow_method === "delete") {
             const triggerURL = common.getTriggerURL(params.authKey, params.endpoint, params.triggerName);
@@ -70,14 +62,16 @@ function main(params) {
                     db = new Database(params.DB_URL, params.DB_NAME);
                     return db.deleteTrigger(params.triggerName);
                 })
-                .then(resolve)
-                .catch(reject);
+                .then(() => {
+                    console.log('successfully deleted the trigger');
+                    resolve(common.webResponse(200, 'deleted trigger'));
+                })
+                .catch(error => {
+                    console.log(`Failed to remove trigger ${error}`);
+                    resolve(common.webResponse(500, error.toString()));
+                });
         } else {
-            resolve({
-                statusCode: 400,
-                headers: {'Content-Type': 'text/plain'},
-                body: 'unsupported lifecycleEvent'
-            });
+            resolve(common.webResponse(400, 'unsupported lifecycleEvent'));
         }
     });
 
diff --git a/action/lib/common.js b/action/lib/common.js
index ffe7b4d..46a7d32 100644
--- a/action/lib/common.js
+++ b/action/lib/common.js
@@ -166,6 +166,16 @@ function performCommonParameterValidation(rawParams) {
     return { validatedParams: validatedParams };
 }
 
+function webResponse(code, body) {
+    return {
+        statusCode: code,
+        headers: {
+            'Content-Type': 'text/plain'
+        },
+        body: body
+    };
+}
+
 module.exports = {
     'createTrigger': createTrigger,
     'deleteTrigger': deleteTrigger,
@@ -176,4 +186,5 @@ module.exports = {
     'performCommonParameterValidation': performCommonParameterValidation,
     'validateBrokerParam': validateBrokerParam,
     'verifyTriggerAuth': verifyTriggerAuth,
+    'webResponse': webResponse
 };
diff --git a/action/messageHubFeedWeb.js b/action/messageHubFeedWeb.js
index 71ad76f..eaa3a18 100644
--- a/action/messageHubFeedWeb.js
+++ b/action/messageHubFeedWeb.js
@@ -38,11 +38,7 @@ function main(params) {
                 .then(() => db.recordTrigger(validatedParams))
                 .then(() => {
                     console.log('successfully wrote the trigger');
-                    resolve({
-                        statusCode: 200,
-                        headers: {'Content-Type': 'text/plain'},
-                        body: validatedParams.uuid
-                    });
+                    resolve(common.webResponse(200, validatedParams.uuid));
                 })
                 .catch(error => {
                     console.log(`Failed to write the trigger ${error}`);
@@ -59,11 +55,7 @@ function main(params) {
                         body = error.authError;
                     }
 
-                    resolve({
-                        statusCode: statusCode,
-                        headers: {'Content-Type': 'text/plain'},
-                        body: body
-                    });
+                    resolve(common.webResponse(statusCode, body));
                 });
         } else if (params.__ow_method === "delete") {
             const triggerURL = common.getTriggerURL(params.authKey, params.endpoint, params.triggerName);
@@ -73,14 +65,16 @@ function main(params) {
                     db = new Database(params.DB_URL, params.DB_NAME);
                     return db.deleteTrigger(params.triggerName);
                 })
-                .then(resolve)
-                .catch(reject);
+                .then(() => {
+                    console.log('successfully deleted the trigger');
+                    resolve(common.webResponse(200, 'deleted trigger'));
+                })
+                .catch(error => {
+                    console.log(`Failed to remove trigger ${error}`);
+                    resolve(common.webResponse(500, error.toString()));
+                });
         } else {
-            resolve({
-                statusCode: 400,
-                headers: {'Content-Type': 'text/plain'},
-                body: 'unsupported lifecycleEvent'
-            });
+            resolve(common.webResponse(400, 'unsupported lifecycleEvent'));
         }
     });
 

-- 
To stop receiving notification emails like this one, please contact
['"commits@openwhisk.apache.org" <commits@openwhisk.apache.org>'].

Mime
View raw message