mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2025-04-28 15:39:46 +00:00
Added exception handling
This commit is contained in:
parent
57af2080f5
commit
1900cd2028
@ -11,9 +11,11 @@ public class ERIClientV1(string baseAddress) : ERIClientBase(baseAddress), IERIC
|
|||||||
#region Implementation of IERIClient
|
#region Implementation of IERIClient
|
||||||
|
|
||||||
public async Task<APIResponse<List<AuthScheme>>> GetAuthMethodsAsync(CancellationToken cancellationToken = default)
|
public async Task<APIResponse<List<AuthScheme>>> GetAuthMethodsAsync(CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
using var response = await this.httpClient.GetAsync("/auth/methods", cancellationToken);
|
using var response = await this.httpClient.GetAsync("/auth/methods", cancellationToken);
|
||||||
if(!response.IsSuccessStatusCode)
|
if (!response.IsSuccessStatusCode)
|
||||||
{
|
{
|
||||||
return new()
|
return new()
|
||||||
{
|
{
|
||||||
@ -23,7 +25,7 @@ public class ERIClientV1(string baseAddress) : ERIClientBase(baseAddress), IERIC
|
|||||||
}
|
}
|
||||||
|
|
||||||
var authMethods = await response.Content.ReadFromJsonAsync<List<AuthScheme>>(JSON_OPTIONS, cancellationToken);
|
var authMethods = await response.Content.ReadFromJsonAsync<List<AuthScheme>>(JSON_OPTIONS, cancellationToken);
|
||||||
if(authMethods is null)
|
if (authMethods is null)
|
||||||
{
|
{
|
||||||
return new()
|
return new()
|
||||||
{
|
{
|
||||||
@ -38,8 +40,27 @@ public class ERIClientV1(string baseAddress) : ERIClientBase(baseAddress), IERIC
|
|||||||
Data = authMethods
|
Data = authMethods
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
catch (TaskCanceledException)
|
||||||
|
{
|
||||||
|
return new()
|
||||||
|
{
|
||||||
|
Successful = false,
|
||||||
|
Message = "Failed to retrieve the authentication methods: the request was canceled either by the user or due to a timeout."
|
||||||
|
};
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return new()
|
||||||
|
{
|
||||||
|
Successful = false,
|
||||||
|
Message = $"Failed to retrieve the authentication methods due to an exception: {e.Message}"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<APIResponse<AuthResponse>> AuthenticateAsync(IERIDataSource dataSource, RustService rustService, CancellationToken cancellationToken = default)
|
public async Task<APIResponse<AuthResponse>> AuthenticateAsync(IERIDataSource dataSource, RustService rustService, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
var authMethod = dataSource.AuthMethod;
|
var authMethod = dataSource.AuthMethod;
|
||||||
var username = dataSource.Username;
|
var username = dataSource.Username;
|
||||||
@ -176,8 +197,27 @@ public class ERIClientV1(string baseAddress) : ERIClientBase(baseAddress), IERIC
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch(TaskCanceledException)
|
||||||
|
{
|
||||||
|
return new()
|
||||||
|
{
|
||||||
|
Successful = false,
|
||||||
|
Message = "Failed to authenticate with the ERI server: the request was canceled either by the user or due to a timeout."
|
||||||
|
};
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return new()
|
||||||
|
{
|
||||||
|
Successful = false,
|
||||||
|
Message = $"Failed to authenticate with the ERI server due to an exception: {e.Message}"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<APIResponse<DataSourceInfo>> GetDataSourceInfoAsync(CancellationToken cancellationToken = default)
|
public async Task<APIResponse<DataSourceInfo>> GetDataSourceInfoAsync(CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
using var request = new HttpRequestMessage(HttpMethod.Get, "/dataSource");
|
using var request = new HttpRequestMessage(HttpMethod.Get, "/dataSource");
|
||||||
request.Headers.Add("token", this.securityToken);
|
request.Headers.Add("token", this.securityToken);
|
||||||
@ -208,8 +248,27 @@ public class ERIClientV1(string baseAddress) : ERIClientBase(baseAddress), IERIC
|
|||||||
Data = dataSourceInfo
|
Data = dataSourceInfo
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
catch(TaskCanceledException)
|
||||||
|
{
|
||||||
|
return new()
|
||||||
|
{
|
||||||
|
Successful = false,
|
||||||
|
Message = "Failed to retrieve the data source information: the request was canceled either by the user or due to a timeout."
|
||||||
|
};
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return new()
|
||||||
|
{
|
||||||
|
Successful = false,
|
||||||
|
Message = $"Failed to retrieve the data source information due to an exception: {e.Message}"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<APIResponse<List<EmbeddingInfo>>> GetEmbeddingInfoAsync(CancellationToken cancellationToken = default)
|
public async Task<APIResponse<List<EmbeddingInfo>>> GetEmbeddingInfoAsync(CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
using var request = new HttpRequestMessage(HttpMethod.Get, "/embedding/info");
|
using var request = new HttpRequestMessage(HttpMethod.Get, "/embedding/info");
|
||||||
request.Headers.Add("token", this.securityToken);
|
request.Headers.Add("token", this.securityToken);
|
||||||
@ -240,8 +299,27 @@ public class ERIClientV1(string baseAddress) : ERIClientBase(baseAddress), IERIC
|
|||||||
Data = embeddingInfo
|
Data = embeddingInfo
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
catch(TaskCanceledException)
|
||||||
|
{
|
||||||
|
return new()
|
||||||
|
{
|
||||||
|
Successful = false,
|
||||||
|
Message = "Failed to retrieve the embedding information: the request was canceled either by the user or due to a timeout."
|
||||||
|
};
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return new()
|
||||||
|
{
|
||||||
|
Successful = false,
|
||||||
|
Message = $"Failed to retrieve the embedding information due to an exception: {e.Message}"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<APIResponse<List<RetrievalInfo>>> GetRetrievalInfoAsync(CancellationToken cancellationToken = default)
|
public async Task<APIResponse<List<RetrievalInfo>>> GetRetrievalInfoAsync(CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
using var request = new HttpRequestMessage(HttpMethod.Get, "/retrieval/info");
|
using var request = new HttpRequestMessage(HttpMethod.Get, "/retrieval/info");
|
||||||
request.Headers.Add("token", this.securityToken);
|
request.Headers.Add("token", this.securityToken);
|
||||||
@ -272,8 +350,27 @@ public class ERIClientV1(string baseAddress) : ERIClientBase(baseAddress), IERIC
|
|||||||
Data = retrievalInfo
|
Data = retrievalInfo
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
catch(TaskCanceledException)
|
||||||
|
{
|
||||||
|
return new()
|
||||||
|
{
|
||||||
|
Successful = false,
|
||||||
|
Message = "Failed to retrieve the retrieval information: the request was canceled either by the user or due to a timeout."
|
||||||
|
};
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return new()
|
||||||
|
{
|
||||||
|
Successful = false,
|
||||||
|
Message = $"Failed to retrieve the retrieval information due to an exception: {e.Message}"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<APIResponse<List<Context>>> ExecuteRetrievalAsync(RetrievalRequest request, CancellationToken cancellationToken = default)
|
public async Task<APIResponse<List<Context>>> ExecuteRetrievalAsync(RetrievalRequest request, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
using var requestMessage = new HttpRequestMessage(HttpMethod.Post, "/retrieval");
|
using var requestMessage = new HttpRequestMessage(HttpMethod.Post, "/retrieval");
|
||||||
requestMessage.Headers.Add("token", this.securityToken);
|
requestMessage.Headers.Add("token", this.securityToken);
|
||||||
@ -307,8 +404,27 @@ public class ERIClientV1(string baseAddress) : ERIClientBase(baseAddress), IERIC
|
|||||||
Data = contexts
|
Data = contexts
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
catch(TaskCanceledException)
|
||||||
|
{
|
||||||
|
return new()
|
||||||
|
{
|
||||||
|
Successful = false,
|
||||||
|
Message = "Failed to execute the retrieval request: the request was canceled either by the user or due to a timeout."
|
||||||
|
};
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return new()
|
||||||
|
{
|
||||||
|
Successful = false,
|
||||||
|
Message = $"Failed to execute the retrieval request due to an exception: {e.Message}"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<APIResponse<SecurityRequirements>> GetSecurityRequirementsAsync(CancellationToken cancellationToken = default)
|
public async Task<APIResponse<SecurityRequirements>> GetSecurityRequirementsAsync(CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
using var request = new HttpRequestMessage(HttpMethod.Get, "/security/requirements");
|
using var request = new HttpRequestMessage(HttpMethod.Get, "/security/requirements");
|
||||||
request.Headers.Add("token", this.securityToken);
|
request.Headers.Add("token", this.securityToken);
|
||||||
@ -339,6 +455,23 @@ public class ERIClientV1(string baseAddress) : ERIClientBase(baseAddress), IERIC
|
|||||||
Data = securityRequirements
|
Data = securityRequirements
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
catch(TaskCanceledException)
|
||||||
|
{
|
||||||
|
return new()
|
||||||
|
{
|
||||||
|
Successful = false,
|
||||||
|
Message = "Failed to retrieve the security requirements: the request was canceled either by the user or due to a timeout."
|
||||||
|
};
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return new()
|
||||||
|
{
|
||||||
|
Successful = false,
|
||||||
|
Message = $"Failed to retrieve the security requirements due to an exception: {e.Message}"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user