Skip to content

Commit

Permalink
Merge pull request #551 from Lezune/users/Lezune/Foundations-AIModels…
Browse files Browse the repository at this point in the history
…-Update

CODE RUB: Foundations AIModels Exceptions Update v2.10.1
  • Loading branch information
glhays authored Jun 12, 2024
2 parents 6fdccc8 + dcaf761 commit 7c6c02a
Show file tree
Hide file tree
Showing 15 changed files with 110 additions and 101 deletions.
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

0 comments on commit 7c6c02a

Please sign in to comment.