mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-24 20:57:19 -08:00
enhance: outputs the response body if OpenAI fails
Some checks are pending
Some checks are pending
Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
parent
efac161b12
commit
b3ebd84af5
1 changed files with 6 additions and 3 deletions
|
@ -169,12 +169,15 @@ namespace SourceGit.Models
|
||||||
task.Wait(cancellation);
|
task.Wait(cancellation);
|
||||||
|
|
||||||
var rsp = task.Result;
|
var rsp = task.Result;
|
||||||
if (!rsp.IsSuccessStatusCode)
|
|
||||||
throw new Exception($"AI service returns error code {rsp.StatusCode}");
|
|
||||||
|
|
||||||
var reader = rsp.Content.ReadAsStringAsync(cancellation);
|
var reader = rsp.Content.ReadAsStringAsync(cancellation);
|
||||||
reader.Wait(cancellation);
|
reader.Wait(cancellation);
|
||||||
|
|
||||||
|
var body = reader.Result;
|
||||||
|
if (!rsp.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
throw new Exception($"AI service returns error code {rsp.StatusCode}. Body: {body??string.Empty}");
|
||||||
|
}
|
||||||
|
|
||||||
return JsonSerializer.Deserialize(reader.Result, JsonCodeGen.Default.OpenAIChatResponse);
|
return JsonSerializer.Deserialize(reader.Result, JsonCodeGen.Default.OpenAIChatResponse);
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
|
|
Loading…
Reference in a new issue