AsterNET.ARI icon indicating copy to clipboard operation
AsterNET.ARI copied to clipboard

Error switch doesn't work

Open reddevilfirst opened this issue 7 years ago • 6 comments

Logic:

if ((int)response.StatusCode >= 200 && (int)response.StatusCode < 300)
                return;
            switch ((int)response.StatusCode)
            {
                case 400:
                    throw new AriException("Invalid reason for hangup provided", (int)response.StatusCode);
                case 404:
                    throw new AriException("Channel not found", (int)response.StatusCode);
                default:
                    // Unknown server response
                    throw new AriException(string.Format("Unknown response code {0} from ARI.", response.StatusCode), (int)response.StatusCode);
            }

and some similar code doesn't work it just throw exception if StatusCode not ok

reddevilfirst avatar Jul 04 '17 13:07 reddevilfirst

Open to suggestions for fixes.

skrusty avatar Jul 04 '17 20:07 skrusty

I know how to fix it, by specifying the values of the StatusCode enum. I'll see if I can work on a patch in the next few days. We still need to get the CI deploy setup sometime.

seiggy avatar Sep 07 '17 01:09 seiggy

Yes @seiggy , feel free to get i touch, could do with your help. :)

skrusty avatar Sep 07 '17 09:09 skrusty

Ok, I was wrong on where the issue with this was. Currently we are trapping the response codes and returning an exception on anything other than a 200 response. You can trap the AriException yourself, and then check the StatusCode on the AriException object if you want to know what the HttpResponseCode is. We can change this if enough people don't like the implementation and just always return the response with the status code instead of throwing an exception. Not sure if that's the best way to handle this, but I'm sure @skrusty is open to discussion on changin this.

seiggy avatar Sep 10 '17 05:09 seiggy

Suggested logic change for you @reddevilfirst

try
{
   var response = ActionClient.Channels.Hangup(e.Channel.Id, "normal");
}
catch (AriException ex)
{
   var statusCode = ex.StatusCode;
}

That will give you the StatusCode for logging or any other info you want to capture.

seiggy avatar Sep 10 '17 06:09 seiggy

So, to be clear, the way it's done now is due to the fact the Swagger file that is exported by ARI defines some exceptions, hence why there is a few per request that have a specific response code and message.

skrusty avatar Sep 13 '17 09:09 skrusty