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 ImageGenerations Exceptions Update v2.10.1 #553

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
dc51a50
Updated ExcessiveCallImageGenerationException class by removing const…
Lezune May 30, 2024
a5202c6
Updated FailedImageGenerationServiceException class by removing const…
Lezune May 30, 2024
09c962a
Updated FailedServerImageGenerationException class by removing constr…
Lezune May 30, 2024
10e28f7
Updated ImageGenerationDependencyException class by removing construc…
Lezune May 30, 2024
092a0ed
Updated ImageGenerationDependencyValidationException class by removin…
Lezune May 30, 2024
f322a78
Updated ImageGenerationServiceException class by removing constructor…
Lezune May 30, 2024
34d6590
Updated ImageGenerationValidationException class by removing construc…
Lezune May 30, 2024
29bffa2
Updated InvalidConfigurationImageGenerationException class by removin…
Lezune May 30, 2024
ba6f05e
Updated InvalidImageGenerationException class by removing constructor…
Lezune May 30, 2024
c5fcb5f
Updated NotFoundImageGenerationException class by removing constructo…
Lezune May 30, 2024
4dbb98c
Updated NullImageGenerationException class by removing constructors i…
Lezune May 30, 2024
83af754
Updated UnauthorizedImageGenerationException class by removing constr…
Lezune May 30, 2024
641830b
Added create methods to both ImageGenerationService.Exceptions.cs and…
Lezune May 31, 2024
ac5ee7d
Added create methods to both ImageGenerationService.Exceptions.cs and…
Lezune May 31, 2024
4c39209
Added create methods to both ImageGenerationService.Exceptions.cs and…
Lezune May 31, 2024
ab6ad11
Added create methods to both ImageGenerationService.Exceptions.cs and…
Lezune May 31, 2024
fef16cb
Added create methods to both ImageGenerationService.Exceptions.cs and…
Lezune May 31, 2024
4cde18d
Updated create method to adhere to method naming standards
Lezune Jun 6, 2024
f9d3b69
Reverted Unit Test files to original state
Lezune Jun 6, 2024
bb8b461
Reverted Unit Test files to original state
Lezune Jun 6, 2024
6748719
Updated create method to adhere to method naming standards
Lezune Jun 6, 2024
1f0bce9
Updated create method to adhere to method naming standards
Lezune Jun 6, 2024
fc335ef
Reverted Unit Test files to original state
Lezune Jun 6, 2024
223dee4
Updated create method to adhere to method naming standards
Lezune Jun 6, 2024
99f86df
Updated create method to adhere to method naming standards
Lezune Jun 6, 2024
fa0a3f8
Merge branch 'users/Lezune/Foundations-ImageGenerations-FailedImageGe…
Lezune Jun 10, 2024
b7a16d7
Merge branch 'users/Lezune/Foundations-ImageGenerations-FailedServerI…
Lezune Jun 10, 2024
3002a19
Merge branch 'users/Lezune/Foundations-ImageGenerations-ImageGenerati…
Lezune Jun 10, 2024
8c1e988
Resolved merge conflicts with users/Lezune/Foundations-ImageGeneratio…
Lezune Jun 10, 2024
a975c4d
Merge branch 'users/Lezune/Foundations-ImageGenerations-ImageGenerati…
Lezune Jun 10, 2024
ebc9aee
Resolved Merged conflicts with users/Lezune/Foundations-ImageGenerati…
Lezune Jun 10, 2024
f775381
Merge branch 'users/Lezune/Foundations-ImageGenerations-InvalidConfig…
Lezune Jun 10, 2024
5c3abdd
Merge branch 'users/Lezune/Foundations-ImageGenerations-InvalidImageG…
Lezune Jun 10, 2024
1f9e776
Merge branch 'users/Lezune/Foundations-ImageGenerations-NotFoundImage…
Lezune Jun 10, 2024
35a46dc
Merge branch 'users/Lezune/Foundations-ImageGenerations-NullImageGene…
Lezune Jun 10, 2024
3ff3a82
Refactored code and merged users/Lezune/Foundations-ImageGenerations-…
Lezune Jun 10, 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 @@ -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
Loading