mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2025-04-28 18:59:47 +00:00
Improved error handling
This commit is contained in:
parent
21927754b6
commit
dc762cc83f
@ -1,3 +1,5 @@
|
|||||||
|
using System.Net;
|
||||||
|
|
||||||
using AIStudio.Chat;
|
using AIStudio.Chat;
|
||||||
|
|
||||||
using RustService = AIStudio.Tools.RustService;
|
using RustService = AIStudio.Tools.RustService;
|
||||||
@ -103,6 +105,13 @@ public abstract class BaseProvider : IProvider, ISecretId
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(nextResponse.StatusCode is HttpStatusCode.BadRequest)
|
||||||
|
{
|
||||||
|
this.logger.LogError($"Failed request with status code {nextResponse.StatusCode} (message = '{nextResponse.ReasonPhrase}').");
|
||||||
|
errorMessage = nextResponse.ReasonPhrase;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
errorMessage = nextResponse.ReasonPhrase;
|
errorMessage = nextResponse.ReasonPhrase;
|
||||||
var timeSeconds = Math.Pow(RETRY_DELAY_SECONDS, retry + 1);
|
var timeSeconds = Math.Pow(RETRY_DELAY_SECONDS, retry + 1);
|
||||||
if(timeSeconds > 90)
|
if(timeSeconds > 90)
|
||||||
@ -112,7 +121,7 @@ public abstract class BaseProvider : IProvider, ISecretId
|
|||||||
await Task.Delay(TimeSpan.FromSeconds(timeSeconds), token);
|
await Task.Delay(TimeSpan.FromSeconds(timeSeconds), token);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(retry >= MAX_RETRIES)
|
if(retry >= MAX_RETRIES || !string.IsNullOrWhiteSpace(errorMessage))
|
||||||
return new HttpRateLimitedStreamResult(false, true, errorMessage ?? $"Failed after {MAX_RETRIES} retries; no provider message available", response);
|
return new HttpRateLimitedStreamResult(false, true, errorMessage ?? $"Failed after {MAX_RETRIES} retries; no provider message available", response);
|
||||||
|
|
||||||
return new HttpRateLimitedStreamResult(true, false, string.Empty, response);
|
return new HttpRateLimitedStreamResult(true, false, string.Empty, response);
|
||||||
|
Loading…
Reference in New Issue
Block a user