res_ari_channels: Return a 404 response when a requested channel variable does not...
authorJoshua Colp <jcolp@digium.com>
Sat, 21 Feb 2015 20:48:17 +0000 (20:48 +0000)
committerJoshua Colp <jcolp@digium.com>
Sat, 21 Feb 2015 20:48:17 +0000 (20:48 +0000)
This change makes it so that if a channel variable is requested and it does not exist
a 404 response will be returned instead of an allocation failed response. This makes
it easier to debug and figure out what is going on for a user.

ASTERISK-24677 #close
Reported by: Joshua Colp
........

Merged revisions 432154 from http://svn.asterisk.org/svn/asterisk/branches/13

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@432155 65c4cc65-6c06-0410-ace0-fbb531ad65f3

res/ari/resource_channels.c
res/res_ari_channels.c
rest-api/api-docs/channels.json

index 67498af..edd319d 100644 (file)
@@ -1242,6 +1242,11 @@ void ast_ari_channels_get_channel_var(struct ast_variable *headers,
 
        ast_assert(response != NULL);
 
+       if (!value) {
+               ast_ari_response_alloc_failed(response);
+               return;
+       }
+
        if (ast_strlen_zero(args->variable)) {
                ast_ari_response_error(
                        response, 400, "Bad Request",
@@ -1280,7 +1285,9 @@ void ast_ari_channels_get_channel_var(struct ast_variable *headers,
                }
        } else {
                if (!ast_str_retrieve_variable(&value, 0, channel, NULL, args->variable)) {
-                       ast_ari_response_alloc_failed(response);
+                       ast_ari_response_error(
+                               response, 404, "Variable Not Found",
+                               "Provided variable was not found");
                        return;
                }
        }
index a088705..0d1334e 100644 (file)
@@ -2173,7 +2173,7 @@ static void ast_ari_channels_get_channel_var_cb(
        case 500: /* Internal Server Error */
        case 501: /* Not Implemented */
        case 400: /* Missing variable parameter. */
-       case 404: /* Channel not found */
+       case 404: /* Channel or variable not found */
        case 409: /* Channel not in a Stasis application */
                is_valid = 1;
                break;
index 9a0a4f3..9bcfda9 100644 (file)
                                                },
                                                {
                                                        "code": 404,
-                                                       "reason": "Channel not found"
+                                                       "reason": "Channel or variable not found"
                                                },
                                                {
                                                        "code": 409,