Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CODE RUB: Foundations AIModels Exceptions Update v2.10.1 #551

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
40463a9
Updated AIModelDependencyException class by removing constructors in …
Lezune May 30, 2024
f0f389d
Updated AIModelDependencyValidationException class by removing constr…
Lezune May 30, 2024
ea0beef
Updated AIModelServiceException class by removing constructors in whi…
Lezune May 30, 2024
2eacc68
Updated AIModelValidationException class by removing constructors in …
Lezune May 30, 2024
637eb37
Updated ExcessiveCallAIModelException class by removing constructors …
Lezune May 30, 2024
0976b7d
Updated FailedAIModelServiceException class by removing constructors …
Lezune May 30, 2024
bb88b36
Updated FailedServerAIModelException class by removing constructors i…
Lezune May 30, 2024
87848a9
Updated InvalidAIModelException class by removing constructors in whi…
Lezune May 30, 2024
fdaf314
Updated InvalidConfigurationAIModelException class by removing constr…
Lezune May 30, 2024
3f67637
Updated NotFoundAIModelException class by removing constructors in wh…
Lezune May 30, 2024
0ae4082
Updated UnauthorizedAIModelException class by removing constructors i…
Lezune May 30, 2024
15e1cda
Updated Service file with createAIModelDependencyException and refact…
Lezune May 31, 2024
bd23c8a
Removed spacing
Lezune May 31, 2024
6d56732
Added createAIModelDependencyValidationException method to service fi…
Lezune May 31, 2024
bf66bfa
Added createAIModelServiceException to the service file and refactore…
Lezune May 31, 2024
dfcd9b8
moved createAIModelDependencyException method to AIModelService.Excep…
Lezune May 31, 2024
4062167
Moved create method to AIModelService.Exceptions
Lezune May 31, 2024
228710e
Moved create method to AIModelService.Exceptions
Lezune May 31, 2024
e8f125b
Added a createExcessiveCallAIModelException method to AIModelsService…
Lezune May 31, 2024
4f4f36a
Added a createExcessiveCallAIModelException method to Unit Test Class
Lezune May 31, 2024
0733d08
Added create methods to the AIModelServiceTests.cs and refactored code
Lezune May 31, 2024
a891181
Added create methods to the AIModelServiceTests.cs and refactored code
Lezune May 31, 2024
1839392
Added create methods to the AIModelServiceTests.cs and refactored code
Lezune May 31, 2024
4450e2f
Added create methods to both AIModelService.Exceptions.cs and AIModel…
Lezune May 31, 2024
38a5c8d
Added create methods to both AIModelService.Exceptions.cs and AIModel…
Lezune May 31, 2024
8815d04
Added create methods to both AIModelService.Exceptions.cs and AIModel…
Lezune May 31, 2024
05dbf31
Added create methods to both AIModelService.Exceptions.cs and AIModel…
Lezune May 31, 2024
35bfe73
Reverted Unit Test files and updated create method declaration and ca…
Lezune Jun 6, 2024
e99a945
Reverted Unit Test files and updated create method declaration and ca…
Lezune Jun 6, 2024
9c019fe
Reverted Unit Test files and updated create method declaration and ca…
Lezune Jun 6, 2024
2d0e35d
Updated create method declaration and calls to adhere to method namin…
Lezune Jun 6, 2024
898a1e5
Reverted Unit Test files and updated create method declaration and ca…
Lezune Jun 6, 2024
5f011ae
Reverted Unit Test files and updated create method declaration and ca…
Lezune Jun 6, 2024
72e828f
Reverted Unit Test files and updated create method declaration and ca…
Lezune Jun 6, 2024
bd7905a
Reverted Unit Test files and updated create method declaration and ca…
Lezune Jun 6, 2024
6b3d370
Reverted Unit Test files and updated create method declaration and ca…
Lezune Jun 6, 2024
e2fc1e2
Reverted Unit Test files and updated create method declaration and ca…
Lezune Jun 6, 2024
4e1e634
Resolved Merge Conflicts with users/Lezune/Foundations-AIModels-AIMod…
Lezune Jun 10, 2024
a38e85b
Resolved Merge Conflicts with users/Lezune/Foundations-AIModels-AIMod…
Lezune Jun 10, 2024
6dd69fb
Merge branch 'users/Lezune/Foundations-AIModels-AIModelValidationExce…
Lezune Jun 10, 2024
60f1ab1
Refactored code and organized Create methods
Lezune Jun 10, 2024
aa846f9
Resolved Merge Conflicts with users/Lezune/Foundations-AIModels-Exces…
Lezune Jun 10, 2024
2b24494
Resolved error and Reorganized Create methods
Lezune Jun 10, 2024
e2ae93b
Resolved merge conflicts with the users/Lezune/Foundations-AIModels-F…
Lezune Jun 10, 2024
dde110f
Resolved Merge Conflicts with users/Lezune/Foundations-AIModels-Faile…
Lezune Jun 10, 2024
e282a64
Merge branch 'users/Lezune/Foundations-AIModels-InvalidAIModelExcepti…
Lezune Jun 10, 2024
dd8f424
Resolved merge conflicts with users/Lezune/Foundations-AIModels-Inval…
Lezune Jun 10, 2024
41cf1a2
Merge branch 'users/Lezune/Foundations-AIModels-NotFoundAIModelExcept…
Lezune Jun 10, 2024
9cb3c83
Resolved merge conflicts with users/Lezune/Foundations-AIModels-Unaut…
Lezune Jun 10, 2024
7d3871c
Refactored code
Lezune Jun 10, 2024
06d379b
Refactored code
Lezune Jun 11, 2024
903d0a4
Refactored Code
Lezune Jun 11, 2024
dcaf761
Removed extra lines
Lezune Jun 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ private async Task ShouldThrowValidationExceptionOnRetrieveModelByNameIfModelNam
{
// given
var invalidAIModelException =
new InvalidAIModelException();
new InvalidAIModelException(
message: "AI Model is invalid.");

invalidAIModelException.AddData(
key: nameof(AIModel.Name),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ namespace Standard.AI.OpenAI.Models.Services.Foundations.AIModels.Exceptions
{
internal class AIModelDependencyException : Xeption
{
public AIModelDependencyException(Xeption innerException)
: base(
message: "AI Model dependency error occurred, contact support.",
innerException: innerException)
{ }

public AIModelDependencyException(string message, Xeption innerException)
: base(message, innerException)
{ }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ namespace Standard.AI.OpenAI.Models.Services.Foundations.AIModels.Exceptions
{
internal class AIModelDependencyValidationException : Xeption
{
public AIModelDependencyValidationException(Xeption innerException)
: base(
message: "AI Model dependency validation error occurred, fix errors and try again.",
innerException: innerException)
{ }

public AIModelDependencyValidationException(string message, Xeption innerException)
: base(message: message, innerException)
{ }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ namespace Standard.AI.OpenAI.Models.Services.Foundations.AIModels.Exceptions
{
public class AIModelServiceException : Xeption
{
public AIModelServiceException(Xeption innerException)
: base(
message: "AI Model service error occurred, contact support.",
innerException: innerException)
{ }

public AIModelServiceException(string message, Xeption innerException)
: base(message, innerException)
{ }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ namespace Standard.AI.OpenAI.Models.Services.Foundations.AIModels.Exceptions
{
public class AIModelValidationException : Xeption
{
public AIModelValidationException(Xeption innerException)
: base(
message: "AI Model validation error occurred, fix errors and try again.",
innerException: innerException)
{ }

public AIModelValidationException(string message, Xeption innerException)
: base(message, innerException)
{ }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ namespace Standard.AI.OpenAI.Models.Services.Foundations.AIModels.Exceptions
{
internal class ExcessiveCallAIModelException : Xeption
{
public ExcessiveCallAIModelException(Exception innerException)
: base(
message: "Excessive call error occurred, limit your calls.",
innerException: innerException)
{ }

public ExcessiveCallAIModelException(string message, Exception innerException)
: base(message, innerException)
{ }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ namespace Standard.AI.OpenAI.Models.Services.Foundations.AIModels.Exceptions
{
public class FailedAIModelServiceException : Xeption
{
public FailedAIModelServiceException(Exception innerException)
: base(
message: "Failed AI Model Service Exception occurred, please contact support for assistance.",
innerException: innerException)
{ }

public FailedAIModelServiceException(string message, Exception innerException)
: base(message, innerException)
{ }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ namespace Standard.AI.OpenAI.Models.Services.Foundations.AIModels.Exceptions
{
public class FailedServerAIModelException : Xeption
{
public FailedServerAIModelException(Exception innerException)
: base(
message: "Failed AI Model server error occurred, contact support",
innerException: innerException)
{ }

public FailedServerAIModelException(string message, Exception innerException)
: base(message, innerException)
{ }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,8 @@ namespace Standard.AI.OpenAI.Models.Services.Foundations.AIModels.Exceptions
{
public class InvalidAIModelException : Xeption
{
public InvalidAIModelException()
: base(
message: "AI Model is invalid.")
{ }

public InvalidAIModelException(Exception innerException)
: base(
message: "AI Model is invalid.",
innerException: innerException)
public InvalidAIModelException(string message)
: base(message)
{ }

public InvalidAIModelException(string message, Exception innerException)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ namespace Standard.AI.OpenAI.Models.Services.Foundations.AIModels.Exceptions
{
public class InvalidConfigurationAIModelException : Xeption
{
public InvalidConfigurationAIModelException(Exception innerException)
: base(
message: "Invalid AI Model configuration error occurred, contact support.",
innerException: innerException)
{ }

public InvalidConfigurationAIModelException(string message, Exception innerException)
: base(message, innerException) { }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ namespace Standard.AI.OpenAI.Models.Services.Foundations.AIModels.Exceptions
{
public class NotFoundAIModelException : Xeption
{
public NotFoundAIModelException(Exception innerException)
: base(
message: "AI Model not found.",
innerException: innerException)
{ }

public NotFoundAIModelException(string message, Exception innerException)
: base(message, innerException)
{ }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,7 @@
namespace Standard.AI.OpenAI.Models.Services.Foundations.AIModels.Exceptions
{
public class UnauthorizedAIModelException : Xeption
{
public UnauthorizedAIModelException(Exception innerException)
: base(
message: "Unauthorized AI Model error occurred, fix errors and try again.",
innerException: innerException)
{ }

{
public UnauthorizedAIModelException(string message, Exception innerException)
: base(message, innerException)
{ }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using RESTFulSense.Exceptions;
using Standard.AI.OpenAI.Models.Services.Foundations.AIModels;
using Standard.AI.OpenAI.Models.Services.Foundations.AIModels.Exceptions;
using Xeptions;

namespace Standard.AI.OpenAI.Services.Foundations.AIModels
{
Expand All @@ -24,63 +25,87 @@ private async ValueTask<AIModel> TryCatch(ReturningAIModelFunction returningAIMo
}
catch (InvalidAIModelException invalidAIModelException)
{
throw new AIModelValidationException(invalidAIModelException);
throw CreateAIModelValidationException(
invalidAIModelException);
}
catch (HttpResponseUrlNotFoundException httpResponseUrlNotFoundException)
{
var invalidConfigurationAIModelException =
new InvalidConfigurationAIModelException(httpResponseUrlNotFoundException);
new InvalidConfigurationAIModelException(
message: "Invalid AI Model configuration error occurred, contact support.",
httpResponseUrlNotFoundException);

throw new AIModelDependencyException(invalidConfigurationAIModelException);
throw CreateAIModelDependencyException(
invalidConfigurationAIModelException);
}
catch (HttpResponseUnauthorizedException httpResponseUnauthorizedException)
{
var unauthorizedAIModelException =
new UnauthorizedAIModelException(httpResponseUnauthorizedException);
new UnauthorizedAIModelException(
message: "Unauthorized AI Model error occurred, fix errors and try again.",
httpResponseUnauthorizedException);

throw new AIModelDependencyException(unauthorizedAIModelException);
throw CreateAIModelDependencyException(
unauthorizedAIModelException);
}
catch (HttpResponseForbiddenException httpResponseForbiddenException)
{
var unauthorizedAIModelException =
new UnauthorizedAIModelException(httpResponseForbiddenException);
new UnauthorizedAIModelException(
message: "Unauthorized AI Model error occurred, fix errors and try again.",
httpResponseForbiddenException);

throw new AIModelDependencyException(unauthorizedAIModelException);
throw CreateAIModelDependencyException(
unauthorizedAIModelException);
}
catch (HttpResponseNotFoundException httpResponseNotFoundException)
{
var notFoundAIModelException =
new NotFoundAIModelException(httpResponseNotFoundException);
new NotFoundAIModelException(
message: "AI Model not found.",
httpResponseNotFoundException);

throw new AIModelDependencyValidationException(notFoundAIModelException);
throw CreateAIModelDependencyValidationException(
notFoundAIModelException);
}
catch (HttpResponseBadRequestException httpResponseBadRequestException)
{
var invalidAIModelException =
new InvalidAIModelException(httpResponseBadRequestException);
new InvalidAIModelException(
message: "AI Model is invalid.",
httpResponseBadRequestException);

throw new AIModelDependencyValidationException(invalidAIModelException);
throw CreateAIModelDependencyValidationException(
invalidAIModelException);
}
catch (HttpResponseTooManyRequestsException httpResponseTooManyRequestsException)
{
var excessiveCallAIModelException =
new ExcessiveCallAIModelException(httpResponseTooManyRequestsException);
new ExcessiveCallAIModelException(
message: "Excessive call error occurred, limit your calls.",
httpResponseTooManyRequestsException);

throw new AIModelDependencyValidationException(excessiveCallAIModelException);
throw CreateAIModelDependencyValidationException(
excessiveCallAIModelException);
}
catch (HttpResponseException httpResponseException)
{
var failedServerAIModelException =
new FailedServerAIModelException(httpResponseException);
new FailedServerAIModelException(
message: "Failed AI Model server error occurred, contact support",
httpResponseException);

throw new AIModelDependencyException(failedServerAIModelException);
throw CreateAIModelDependencyException(
failedServerAIModelException);
}
catch (Exception exception)
{
var failedAIModelServiceException =
new FailedAIModelServiceException(exception);
new FailedAIModelServiceException(
message: "Failed AI Model Service Exception occurred, please contact support for assistance.",
exception);

throw new AIModelServiceException(
throw CreateAIModelServiceException(
failedAIModelServiceException);
}
}
Expand All @@ -94,46 +119,92 @@ private async ValueTask<IEnumerable<AIModel>> TryCatch(ReturningAIModelsFunction
catch (HttpResponseUrlNotFoundException httpResponseUrlNotFoundException)
{
var invalidConfigurationAIModelException =
new InvalidConfigurationAIModelException(httpResponseUrlNotFoundException);
new InvalidConfigurationAIModelException(
message: "Invalid AI Model configuration error occurred, contact support.",
httpResponseUrlNotFoundException);

throw new AIModelDependencyException(invalidConfigurationAIModelException);
throw CreateAIModelDependencyException(
invalidConfigurationAIModelException);
}
catch (HttpResponseUnauthorizedException httpResponseUnauthorizedException)
{
var unauthorizedAIModelException =
new UnauthorizedAIModelException(httpResponseUnauthorizedException);
new UnauthorizedAIModelException(
message: "Unauthorized AI Model error occurred, fix errors and try again.",
httpResponseUnauthorizedException);

throw new AIModelDependencyException(unauthorizedAIModelException);
throw CreateAIModelDependencyException(
unauthorizedAIModelException);
}
catch (HttpResponseForbiddenException httpResponseForbiddenException)
{
var unauthorizedAIModelException =
new UnauthorizedAIModelException(httpResponseForbiddenException);
new UnauthorizedAIModelException(
message: "Unauthorized AI Model error occurred, fix errors and try again.",
httpResponseForbiddenException);

throw new AIModelDependencyException(unauthorizedAIModelException);
throw CreateAIModelDependencyException(
unauthorizedAIModelException);
}
catch (HttpResponseTooManyRequestsException httpResponseTooManyRequestsException)
{
var excessiveCallAIModelException =
new ExcessiveCallAIModelException(httpResponseTooManyRequestsException);
new ExcessiveCallAIModelException(
message: "Excessive call error occurred, limit your calls.",
httpResponseTooManyRequestsException);

throw new AIModelDependencyValidationException(excessiveCallAIModelException);
throw CreateAIModelDependencyValidationException(
excessiveCallAIModelException);
}
catch (HttpResponseException httpResponseException)
{
var failedServerAIModelException =
new FailedServerAIModelException(httpResponseException);
new FailedServerAIModelException(
message: "Failed AI Model server error occurred, contact support",
httpResponseException);

throw new AIModelDependencyException(failedServerAIModelException);
throw CreateAIModelDependencyException(
failedServerAIModelException);
}
catch (Exception exception)
{
var failedAIModelServiceException =
new FailedAIModelServiceException(exception);
new FailedAIModelServiceException(
message: "Failed AI Model Service Exception occurred, please contact support for assistance.",
exception);

throw new AIModelServiceException(
throw CreateAIModelServiceException(
failedAIModelServiceException);
}
}

private static AIModelValidationException CreateAIModelValidationException(Xeption innerException)
{
return new AIModelValidationException(
message: "AI Model validation error occurred, fix errors and try again.",
innerException);
}

private static AIModelDependencyException CreateAIModelDependencyException(Xeption innerException)
{
return new AIModelDependencyException(
message: "AI Model dependency error occurred, contact support.",
innerException);
}

private static AIModelDependencyValidationException
CreateAIModelDependencyValidationException(Xeption innerException)
{
return new AIModelDependencyValidationException(
message: "AI Model dependency validation error occurred, fix errors and try again.",
innerException);
}

private static AIModelServiceException CreateAIModelServiceException(Xeption innerException)
{
return new AIModelServiceException(
message: "AI Model service error occurred, contact support.",
innerException);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ private static void ValidateAIModelName(string aiModelName) =>

private static void Validate(params (dynamic Rule, string Parameter)[] validations)
{
var invalidAIModelException = new InvalidAIModelException();
var invalidAIModelException =
new InvalidAIModelException(
message: "AI Model is invalid.");

foreach ((dynamic rule, string parameter) in validations)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
using Standard.AI.OpenAI.Brokers.DateTimes;
using Standard.AI.OpenAI.Brokers.OpenAIs;
using Standard.AI.OpenAI.Models.Services.Foundations.AIModels;
using Standard.AI.OpenAI.Models.Services.Foundations.AIModels.Exceptions;
using Standard.AI.OpenAI.Models.Services.Foundations.ExternalAIModels;
using Xeptions;

namespace Standard.AI.OpenAI.Services.Foundations.AIModels
{
Expand Down
Loading