Closed SkyQuant closed 7 years ago
Hello @SkyQuant Use try catch will capture stack trace.
var container = new Container();
container.RegisterSingleton<IServiceProvider>(container);
container.Register<IApiAiAppServiceFactory, ApiAiAppServiceFactory>();
container.Register<IHttpClientFactory, HttpClientFactory>();
var apiAiAppServiceFactory = container.GetInstance<IApiAiAppServiceFactory>();
var queryAppService = apiAiAppServiceFactory.CreateQueryAppService("https://api.api.ai/v1",
"my_token");
var queryRequest = new QueryRequest
{
Query = new string[] { "Hello, I want a pizza" },
Lang = Api.Ai.Domain.Enum.Language.English
};
try
{
var queryResponsePost = await queryAppService.PostQueryAsync(queryRequest);
}
catch (HttpResponseException ex)
{
var description = ex.StackTrace;
}
You are using api.ai developer access token in my_token parameter?
There is no such exception if method PostQueryAsync is synchronous. But it is in async console app.
static void Main(string[] args)
{
AiRun().GetAwaiter().GetResult();
// AiRun().Wait();
Console.ReadKey();
}
private static async Task AiRun()
{
var container = new Container();
container.RegisterSingleton<IServiceProvider>(container);
container.Register<IApiAiAppServiceFactory, ApiAiAppServiceFactory>();
container.Register<IHttpClientFactory, HttpClientFactory>();
var apiAiAppServiceFactory = container.GetInstance<IApiAiAppServiceFactory>();
var queryAppService = apiAiAppServiceFactory.CreateQueryAppService("https://api.api.ai/v1",
"My Developer Or Client access token");
var queryRequest = new QueryRequest
{
Query = new string[] { "Hello, I want a pizza" },
Lang = Api.Ai.Domain.Enum.Language.English
};
try
{
var queryResponsePost = await queryAppService.PostQueryAsync(queryRequest);
}
catch (HttpResponseException ex)
{
var description = ex.StackTrace;
Debugger.Break();
}
}
Hi @SkyQuant I just publish a new nuget package version (1.0.2) with ApiAiException object to better describe api.ai response error.
I identified that my example does not contains the sessionId field and he is required.
Update your Api.Ai.Csharp package and add sessionId property in the QueryRequest object. 😉
var queryRequest = new QueryRequest
{
SessionId = "1",
Query = new string[] { "Hello, I want a pizza" },
Lang = Api.Ai.Domain.Enum.Language.English
};
I have an exception An unhandled exception of type 'System.Web.Http.HttpResponseException' occurred in mscorlib.dll. Additional information: Processing of the HTTP request resulted in an exception. Please see the HTTP response returned by the 'Response' property of this exception for details. on this code: