Skip to content

Commit

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

CODE RUB: Foundations ImageGenerations Exceptions Update v2.10.1
  • Loading branch information
glhays committed Jun 12, 2024
2 parents 1844472 + 3ff3a82 commit 49ee3e9
Show file tree
Hide file tree
Showing 16 changed files with 92 additions and 95 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ private async Task ShouldThrowValidationExceptionOnGenerateIfImageGenerationIsNu
ImageGeneration nullImageGeneration = null;

var nullImageGenerationException =
new NullImageGenerationException();
new NullImageGenerationException(
message: "Image generation is null.");

var expectedImageGenerationValidationException =
new ImageGenerationValidationException(
Expand Down Expand Up @@ -58,7 +59,7 @@ private async Task ShouldThrowValidationExceptionOnGenerateIfRequestIsNullAsync(
invalidImageGeneration.Request = null;

var invalidImageGenerationException =
new InvalidImageGenerationException();
CreateInvalidImageGenerationException();

invalidImageGenerationException.AddData(
key: nameof(ImageGeneration.Request),
Expand Down Expand Up @@ -106,7 +107,7 @@ private async Task ShouldThrowValidationExceptionOnGenerateIfRequestIsInvalidAsy
};

var invalidImageGenerationException =
new InvalidImageGenerationException();
CreateInvalidImageGenerationException();

invalidImageGenerationException.AddData(
key: nameof(ImageGeneration.Request.Prompt),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Standard.AI.OpenAI.Brokers.OpenAIs;
using Standard.AI.OpenAI.Models.Services.Foundations.ExternalImageGenerations;
using Standard.AI.OpenAI.Models.Services.Foundations.ImageGenerations;
using Standard.AI.OpenAI.Models.Services.Foundations.ImageGenerations.Exceptions;
using Standard.AI.OpenAI.Services.Foundations.ImageGenerations;
using Tynamix.ObjectFiller;
using Xunit;
Expand Down Expand Up @@ -107,5 +108,11 @@ public static TheoryData UnauthorizedExceptions()
new HttpResponseForbiddenException()
};
}

private static InvalidImageGenerationException CreateInvalidImageGenerationException()
{
return new InvalidImageGenerationException(
message: "Invalid image generation error occurred, fix errors and try again.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ namespace Standard.AI.OpenAI.Models.Services.Foundations.ImageGenerations.Except
{
public class ExcessiveCallImageGenerationException : Xeption
{
public ExcessiveCallImageGenerationException(Exception innerException)
: base(
message: "Excessive call error occurred, limit your calls.",
innerException: innerException)
{ }

public ExcessiveCallImageGenerationException(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.ImageGenerations.Except
{
public class FailedImageGenerationServiceException : Xeption
{
public FailedImageGenerationServiceException(Exception innerException)
: base(
message: "Failed image generation service error occurred, contact support.",
innerException: innerException)
{ }

public FailedImageGenerationServiceException(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.ImageGenerations.Except
{
public class FailedServerImageGenerationException : Xeption
{
public FailedServerImageGenerationException(Exception innerException)
: base(
message: "Failed image generation server error occurred, contact support.",
innerException: innerException)
{ }

public FailedServerImageGenerationException(string message, Exception 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.ImageGenerations.Except
{
public class ImageGenerationDependencyException : Xeption
{
public ImageGenerationDependencyException(Xeption innerException)
: base(
message: "Image generation dependency error occurred, contact support.",
innerException: innerException)
{ }

public ImageGenerationDependencyException(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.ImageGenerations.Except
{
public class ImageGenerationDependencyValidationException : Xeption
{
public ImageGenerationDependencyValidationException(Xeption innerException)
: base(
message: "Image generation dependency validation error occurred, fix errors and try again.",
innerException: innerException)
{ }

public ImageGenerationDependencyValidationException(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.ImageGenerations.Except
{
public class ImageGenerationServiceException : Xeption
{
public ImageGenerationServiceException(Exception innerException)
: base(
message: "Image generation service error occurred, contact support.",
innerException: innerException)
{ }

public ImageGenerationServiceException(string message, Exception 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.ImageGenerations.Except
{
public class ImageGenerationValidationException : Xeption
{
public ImageGenerationValidationException(Xeption innerException)
: base(
message: "Image generation validation error occurred, fix errors and try again.",
innerException: innerException)
{ }

public ImageGenerationValidationException(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.ImageGenerations.Except
{
public class InvalidConfigurationImageGenerationException : Xeption
{
public InvalidConfigurationImageGenerationException(Exception innerException)
: base(
message: "Invalid image generation configuration error occurred, contact support.",
innerException: innerException)
{ }

public InvalidConfigurationImageGenerationException(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.ImageGenerations.Except
{
public class InvalidImageGenerationException : Xeption
{
public InvalidImageGenerationException()
: base(
message: "Invalid image generation error occurred, fix errors and try again.")
{ }

public InvalidImageGenerationException(Exception innerException)
: base(
message: "Invalid image generation error occurred, fix errors and try again.",
innerException: innerException)
public InvalidImageGenerationException(string message)
: base(message)
{ }

public InvalidImageGenerationException(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.ImageGenerations.Except
{
public class NotFoundImageGenerationException : Xeption
{
public NotFoundImageGenerationException(Exception innerException)
: base(
message: "Not found image generation error occurred, fix errors and try again.",
innerException: innerException)
{ }

public NotFoundImageGenerationException(string message, Exception innerException)
: base(message, innerException)
{ }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ namespace Standard.AI.OpenAI.Models.Services.Foundations.ImageGenerations.Except
{
public class NullImageGenerationException : Xeption
{
public NullImageGenerationException()
: base(
message: "Image generation is null.")
public NullImageGenerationException(string message)
: base(message)
{ }

public NullImageGenerationException(string message, Xeption 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.ImageGenerations.Except
{
public class UnauthorizedImageGenerationException : Xeption
{
public UnauthorizedImageGenerationException(Exception innerException)
: base(
message: "Unauthorized image generation request, fix errors and try again.",
innerException: innerException)
{ }

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

namespace Standard.AI.OpenAI.Services.Foundations.ImageGenerations
{
Expand All @@ -22,68 +23,121 @@ private async ValueTask<ImageGeneration> TryCatch(ReturningImageGenerationFuncti
}
catch (NullImageGenerationException nullImageGenerationException)
{
throw new ImageGenerationValidationException(nullImageGenerationException);
throw CreateImageGenerationValidationException(
nullImageGenerationException);
}
catch (InvalidImageGenerationException invalidImageGenerationException)
{
throw new ImageGenerationValidationException(invalidImageGenerationException);
throw CreateImageGenerationValidationException(
invalidImageGenerationException);
}
catch (HttpResponseUrlNotFoundException httpResponseUrlNotFoundException)
{
var invalidConfigurationImageGenerationException =
new InvalidConfigurationImageGenerationException(httpResponseUrlNotFoundException);
new InvalidConfigurationImageGenerationException(
message: "Invalid image generation configuration error occurred, contact support.",
httpResponseUrlNotFoundException);

throw new ImageGenerationDependencyException(invalidConfigurationImageGenerationException);
throw CreateImageGenerationDependencyException(
invalidConfigurationImageGenerationException);
}
catch (HttpResponseUnauthorizedException httpResponseUnauthorizedException)
{
var unauthorizedImageGenerationException =
new UnauthorizedImageGenerationException(httpResponseUnauthorizedException);
new UnauthorizedImageGenerationException(
message: "Unauthorized image generation request, fix errors and try again.",
httpResponseUnauthorizedException);

throw new ImageGenerationDependencyException(unauthorizedImageGenerationException);
throw CreateImageGenerationDependencyException(
unauthorizedImageGenerationException);
}
catch (HttpResponseForbiddenException httpResponseForbiddenException)
{
var unauthorizedImageGenerationException =
new UnauthorizedImageGenerationException(httpResponseForbiddenException);
new UnauthorizedImageGenerationException(
message: "Unauthorized image generation request, fix errors and try again.",
httpResponseForbiddenException);

throw new ImageGenerationDependencyException(unauthorizedImageGenerationException);
throw CreateImageGenerationDependencyException(
unauthorizedImageGenerationException);
}
catch (HttpResponseNotFoundException httpResponseNotFoundException)
{
var notFoundImageGenerationException =
new NotFoundImageGenerationException(httpResponseNotFoundException);
new NotFoundImageGenerationException(
message: "Not found image generation error occurred, fix errors and try again.",
httpResponseNotFoundException);

throw new ImageGenerationDependencyValidationException(notFoundImageGenerationException);
throw CreateImageGenerationDependencyValidationException(
notFoundImageGenerationException);
}
catch (HttpResponseBadRequestException httpResponseBadRequestException)
{
var invalidImageGenerationException =
new InvalidImageGenerationException(httpResponseBadRequestException);
new InvalidImageGenerationException(
message: "Invalid image generation error occurred, fix errors and try again.",
httpResponseBadRequestException);

throw new ImageGenerationDependencyValidationException(invalidImageGenerationException);
throw CreateImageGenerationDependencyValidationException(
invalidImageGenerationException);
}
catch (HttpResponseTooManyRequestsException httpResponseTooManyRequestsException)
{
var excessiveCallImageGenerationException =
new ExcessiveCallImageGenerationException(httpResponseTooManyRequestsException);
new ExcessiveCallImageGenerationException(
message: "Excessive call error occurred, limit your calls.",
httpResponseTooManyRequestsException);

throw new ImageGenerationDependencyValidationException(excessiveCallImageGenerationException);
throw CreateImageGenerationDependencyValidationException(
excessiveCallImageGenerationException);
}
catch (HttpResponseException httpResponseException)
{
var failedServerImageGenerationException =
new FailedServerImageGenerationException(httpResponseException);
new FailedServerImageGenerationException(
message: "Failed image generation server error occurred, contact support.",
httpResponseException);

throw new ImageGenerationDependencyException(failedServerImageGenerationException);
throw CreateImageGenerationDependencyException(
failedServerImageGenerationException);
}
catch (Exception exception)
{
var failedImageGenerationServiceException =
new FailedImageGenerationServiceException(exception);
new FailedImageGenerationServiceException(
message: "Failed image generation service error occurred, contact support.",
exception);

throw new ImageGenerationServiceException(failedImageGenerationServiceException);
throw CreateImageGenerationServiceException(failedImageGenerationServiceException);
}
}

private static ImageGenerationValidationException CreateImageGenerationValidationException(Xeption innerException)
{
return new ImageGenerationValidationException(
message: "Image generation validation error occurred, fix errors and try again.",
innerException);
}

private static ImageGenerationDependencyException CreateImageGenerationDependencyException(Xeption innerException)
{
return new ImageGenerationDependencyException(
message: "Image generation dependency error occurred, contact support.",
innerException);
}

private static ImageGenerationDependencyValidationException CreateImageGenerationDependencyValidationException(Xeption innerException)
{
return new ImageGenerationDependencyValidationException(
message: "Image generation dependency validation error occurred, fix errors and try again.",
innerException);
}

private static ImageGenerationServiceException CreateImageGenerationServiceException(Exception innerException)
{
return new ImageGenerationServiceException(
message: "Image generation service error occurred, contact support.",
innerException);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ private static void ValidateImageGenerationIsNotNull(ImageGeneration imageGenera
{
if (imageGeneration is null)
{
throw new NullImageGenerationException();
throw new NullImageGenerationException(
message: "Image generation is null.");
}
}

Expand All @@ -45,7 +46,9 @@ private static void ValidateImageGenerationIsNotNull(ImageGeneration imageGenera

private static void Validate(params (dynamic Rule, string Parameter)[] validations)
{
var invalidImageGenerationException = new InvalidImageGenerationException();
var invalidImageGenerationException =
new InvalidImageGenerationException(
message: "Invalid image generation error occurred, fix errors and try again.");

foreach ((dynamic rule, string parameter) in validations)
{
Expand Down

0 comments on commit 49ee3e9

Please sign in to comment.