Skip to content

Commit

Permalink
Refactored code and merged users/Lezune/Foundations-ImageGenerations-…
Browse files Browse the repository at this point in the history
…UnauthorizedImageGenerationException-Update branch
  • Loading branch information
Lezune committed Jun 10, 2024
2 parents 35a46dc + 99f86df commit 3ff3a82
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
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 @@ -44,15 +44,19 @@ private async ValueTask<ImageGeneration> TryCatch(ReturningImageGenerationFuncti
catch (HttpResponseUnauthorizedException httpResponseUnauthorizedException)
{
var unauthorizedImageGenerationException =
new UnauthorizedImageGenerationException(httpResponseUnauthorizedException);
new UnauthorizedImageGenerationException(
message: "Unauthorized image generation request, fix errors and try again.",
httpResponseUnauthorizedException);

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 CreateImageGenerationDependencyException(
unauthorizedImageGenerationException);
Expand Down Expand Up @@ -104,12 +108,17 @@ private async ValueTask<ImageGeneration> TryCatch(ReturningImageGenerationFuncti
message: "Failed image generation service error occurred, contact support.",
exception);

throw new ImageGenerationServiceException(
message: "Image generation service error occurred, contact support.",
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(
Expand All @@ -124,10 +133,10 @@ private static ImageGenerationDependencyValidationException CreateImageGeneratio
innerException);
}

private static ImageGenerationValidationException CreateImageGenerationValidationException(Xeption innerException)
private static ImageGenerationServiceException CreateImageGenerationServiceException(Exception innerException)
{
return new ImageGenerationValidationException(
message: "Image generation validation error occurred, fix errors and try again.",
return new ImageGenerationServiceException(
message: "Image generation service error occurred, contact support.",
innerException);
}
}
Expand Down

0 comments on commit 3ff3a82

Please sign in to comment.