Add tests for creating trigger with an invalid feed from CLI.
Modified CLI output on action invoke so that the activation result is projected correctly for 200, 500 and 502 activations.
Removed "response:" prefix on blocking activation result.
diff --git a/tools/cli/wskaction.py b/tools/cli/wskaction.py
index 8ae8e59..26b333d 100644
--- a/tools/cli/wskaction.py
+++ b/tools/cli/wskaction.py
@@ -22,7 +22,7 @@
 import urllib
 import subprocess
 from wskitem import Item
-from wskutil import addAuthenticatedCommand, bold, request, getParams, getActivationArgument, getAnnotations, responseError, parseQName, getQName, apiBase, getPrettyJson
+from wskutil import addAuthenticatedCommand, request, getParams, getActivationArgument, getAnnotations, responseError, parseQName, getQName, apiBase, getPrettyJson
 
 #
 # 'wsk actions' CLI
@@ -112,20 +112,22 @@
 
     def invoke(self, args, props):
         res = self.doInvoke(args, props)
-        # OK implies successful blocking invoke
-        # ACCEPTED implies non-blocking
-        # All else are failures
-        if res.status == httplib.OK or res.status == httplib.ACCEPTED:
+        try:
             result = json.loads(res.read())
-            if not (args.result and args.blocking and res.status == httplib.OK):
+            if 'activationId' in result: # if args.result is true, there is no activation id
                 print 'ok: invoked %(name)s with id %(id)s' % {'name': args.name, 'id': result['activationId'] }
-            if res.status == httplib.OK and args.result:
-                print getPrettyJson(result)
-            elif res.status == httplib.OK :
-                print bold('response:')
-                print getPrettyJson(result)
-            return 0
-        else:
+            if res.status == httplib.OK: # true iff args.blocking is true
+                print getPrettyJson(result) # prints the activation or just the result if args.result
+                return 0
+            elif res.status == httplib.ACCEPTED:
+                return 0 if not args.blocking else res.status
+            elif res.status == httplib.BAD_GATEWAY:
+                return responseError(res, prefix = '', flatten = False)
+            elif res.status == httplib.INTERNAL_SERVER_ERROR and 'code' not in result:
+                return responseError(res, prefix = '', flatten = False)
+            else:
+                return responseError(res)
+        except:
             return responseError(res)
 
     # invokes the action and returns HTTP response
@@ -136,7 +138,7 @@
             'namespace': urllib.quote(namespace),
             'name': self.getSafeName(pname),
             'blocking': 'true' if args.blocking else 'false',
-            'result': 'true' if args.result else 'false'
+            'result': 'true' if 'result' in args and args.result else 'false'
         }
         payload = json.dumps(getActivationArgument(args))
         headers = {
diff --git a/tools/cli/wsktrigger.py b/tools/cli/wsktrigger.py
index 059a025..cfd3441 100644
--- a/tools/cli/wsktrigger.py
+++ b/tools/cli/wsktrigger.py
@@ -127,14 +127,19 @@
             'auth': args.auth
         }
 
-        feedResponse = Action().doInvoke(dict2obj(feedArgs), props)
-        if feedResponse.status == httplib.OK:
+        try:
+            feedResponse = Action().doInvoke(dict2obj(feedArgs), props)
+        except Exception as e:
+            print 'exception: %s' % e
+            feedResponse = None
+
+        if feedResponse and feedResponse.status == httplib.OK:
             print 'ok: created %s feed %s' % (self.name, args.name)
         else:
             print 'error: failed to create %s feed %s' % (self.name, args.name)
             # clean up by deleting trigger
             self.httpDelete(args, props)
-            return responseError(feedResponse, None)
+            return responseError(feedResponse, None) if feedResponse else 1
 
     def deleteFeed(self, args, props, res):
         trigger = json.loads(res.read())
@@ -158,9 +163,14 @@
                 'auth': args.auth
             }
 
-            feedResponse = Action().doInvoke(dict2obj(feedArgs), props)
-            if feedResponse.status == httplib.OK:
+            try:
+                feedResponse = Action().doInvoke(dict2obj(feedArgs), props)
+            except Exception as e:
+                print 'exception: %s' % e
+                feedResponse = None
+
+            if feedResponse and feedResponse.status == httplib.OK:
                 return self.deleteResponse(args, res)
             else:
                 print 'error: failed to delete %s feed %s but did delete the trigger' % (self.name, args.name)
-                return responseError(feedResponse, None)
+                return responseError(feedResponse, None) if feedResponse else 1
diff --git a/tools/cli/wskutil.py b/tools/cli/wskutil.py
index 4d74ad0..83a2c6b 100644
--- a/tools/cli/wskutil.py
+++ b/tools/cli/wskutil.py
@@ -99,7 +99,7 @@
         res = dict2obj({ 'status' : 500, 'error': str(e) })
         return res
 
-def responseError(res, prefix = 'error:'):
+def responseError(res, prefix = 'error:', flatten = True):
     if prefix:
         print prefix,
     response = None
@@ -108,7 +108,7 @@
         result = json.loads(response)
         if 'error' in result and 'code' in result:
             print '%s (code %s)' % (result['error'], result['code'])
-        elif 'error' in result:
+        elif 'error' in result and flatten:
             print result['error']
         else:
             print getPrettyJson(result)