AsterNET.ARI
AsterNET.ARI copied to clipboard
Error switch doesn't work
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
Open to suggestions for fixes.
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.
Yes @seiggy , feel free to get i touch, could do with your help. :)
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.
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.
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.