Skip to content

Commit

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

CODE RUB: Foundations AudioTranscriptions Exceptions Update v2.10.1
  • Loading branch information
glhays authored Jun 12, 2024
2 parents 6910519 + d185443 commit 625e735
Show file tree
Hide file tree
Showing 14 changed files with 90 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ private async Task ShouldThrowValidationExceptionOnSendIfAudioTranscriptionIsNul
// given
AudioTranscription audioTranscription = null;

var nullAudioTranscriptionException = new NullAudioTranscriptionException();
var nullAudioTranscriptionException = new NullAudioTranscriptionException(
message: "Audio transcription is null.");

var exceptedAudioTranscriptionValidationException =
new AudioTranscriptionValidationException(
Expand Down Expand Up @@ -56,7 +57,9 @@ private async Task ShouldThrowValidationExceptionOnSendIfAudioTranscriptionReque
Request = null
};

var invalidAudioTranscriptionException = new InvalidAudioTranscriptionException();
var invalidAudioTranscriptionException =
new InvalidAudioTranscriptionException(
message: "Audio transcription is invalid.");

invalidAudioTranscriptionException.AddData(
key: nameof(AudioTranscription.Request),
Expand Down Expand Up @@ -103,7 +106,9 @@ private async Task ShouldThrowValidationExceptionOnSendIfAudioTranscriptionReque
}
};

var invalidAudioTranscriptionException = new InvalidAudioTranscriptionException();
var invalidAudioTranscriptionException =
new InvalidAudioTranscriptionException(
message: "Audio transcription is invalid.");

invalidAudioTranscriptionException.AddData(
key: nameof(AudioTranscriptionRequest.FileName),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using RESTFulSense.Exceptions;
using Standard.AI.OpenAI.Brokers.OpenAIs;
using Standard.AI.OpenAI.Models.Services.Foundations.AudioTranscriptions;
using Standard.AI.OpenAI.Models.Services.Foundations.AudioTranscriptions.Exceptions;
using Standard.AI.OpenAI.Models.Services.Foundations.ExternalAudioTranscriptions;
using Standard.AI.OpenAI.Services.Foundations.AudioTranscriptions;
using Tynamix.ObjectFiller;
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.AudioTranscriptions.Exc
#pragma warning disable RCS1194 // Implement exception constructors.
public class AudioTranscriptionDependencyException : Xeption
{
public AudioTranscriptionDependencyException(Xeption innerException)
: base(
message: "Audio transcription dependency error occurred, contact support.",
innerException: innerException)
{ }

public AudioTranscriptionDependencyException(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.AudioTranscriptions.Exc
#pragma warning disable RCS1194 // Implement exception constructors.
public class AudioTranscriptionDependencyValidationException : Xeption
{
public AudioTranscriptionDependencyValidationException(Xeption innerException)
: base(
message: "Chat completion dependency validation error occurred, fix errors and try again.",
innerException: innerException)
{ }

public AudioTranscriptionDependencyValidationException(string message, Xeption innerException)
: base(message, innerException)
{ }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ namespace Standard.AI.OpenAI.Models.Services.Foundations.AudioTranscriptions.Exc
#pragma warning disable RCS1194 // Implement exception constructors.
public class AudioTranscriptionServiceException : Xeption
{
public AudioTranscriptionServiceException(Exception innerException)
: base(
message: "Audio transcription service error occurred, contact support.",
innerException: innerException)
{ }

public AudioTranscriptionServiceException(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.AudioTranscriptions.Exc
#pragma warning disable RCS1194 // Implement exception constructors.
public class AudioTranscriptionValidationException : Xeption
{
public AudioTranscriptionValidationException(Xeption innerException)
: base(
message: "Audio transcription validation error occurred, fix errors and try again.",
innerException: innerException)
{ }

public AudioTranscriptionValidationException(string message, Xeption innerException)
: base(message, innerException)
{ }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ namespace Standard.AI.OpenAI.Models.Services.Foundations.AudioTranscriptions.Exc
#pragma warning disable RCS1194 // Implement exception constructors.
public class ExcessiveCallAudioTranscriptionException : Xeption
{
public ExcessiveCallAudioTranscriptionException(Exception innerException)
: base(
message: "Excessive call error occurred, limit your calls.",
innerException: innerException)
{ }

public ExcessiveCallAudioTranscriptionException(string message, Exception innerException)
: base(message, innerException)
{ }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ namespace Standard.AI.OpenAI.Models.Services.Foundations.AudioTranscriptions.Exc
#pragma warning disable RCS1194 // Implement exception constructors.
public class FailedAudioTranscriptionServiceException : Xeption
{
public FailedAudioTranscriptionServiceException(Exception innerException)
: base(
message: "Failed Audio Transcription Service Exception occurred, please contact support for assistance.",
innerException: innerException)
{ }

public FailedAudioTranscriptionServiceException(string message, Exception innerException)
: base(message, innerException)
{ }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,8 @@ namespace Standard.AI.OpenAI.Models.Services.Foundations.AudioTranscriptions.Exc
#pragma warning disable RCS1194 // Implement exception constructors.
public class InvalidAudioTranscriptionException : Xeption
{
public InvalidAudioTranscriptionException()
: base(
message: "Audio transcription is invalid.")
{ }

public InvalidAudioTranscriptionException(Exception innerException)
: base(
message: "Audio transcription is invalid.",
innerException: innerException)
public InvalidAudioTranscriptionException(string message)
: base(message)
{ }

public InvalidAudioTranscriptionException(string message, Exception innerException)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ namespace Standard.AI.OpenAI.Models.Services.Foundations.AudioTranscriptions.Exc
#pragma warning disable RCS1194 // Implement exception constructors.
public class InvalidConfigurationAudioTranscriptionException : Xeption
{
public InvalidConfigurationAudioTranscriptionException(Exception innerException)
: base(
message: "Invalid audio transcription configuration error occurred, contact support.",
innerException: innerException)
{ }

public InvalidConfigurationAudioTranscriptionException(string message, Exception innerException)
: base(message, innerException)
{ }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ namespace Standard.AI.OpenAI.Models.Services.Foundations.AudioTranscriptions.Exc
#pragma warning disable RCS1194 // Implement exception constructors.
public class NullAudioTranscriptionException : Xeption
{
public NullAudioTranscriptionException()
: base(
message: "Audio transcription is null.")
public NullAudioTranscriptionException(string message)
: base(message)
{ }

public NullAudioTranscriptionException(string message, Xeption innerException)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ namespace Standard.AI.OpenAI.Models.Services.Foundations.AudioTranscriptions.Exc
#pragma warning disable RCS1194 // Implement exception constructors.
public class UnauthorizedAudioTranscriptionException : Xeption
{
public UnauthorizedAudioTranscriptionException(Exception innerException)
: base(
message: "Unauthorized audio transcription request, fix errors and try again.",
innerException: innerException)
{ }

public UnauthorizedAudioTranscriptionException(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.AudioTranscriptions;
using Standard.AI.OpenAI.Models.Services.Foundations.AudioTranscriptions.Exceptions;
using Xeptions;

namespace Standard.AI.OpenAI.Services.Foundations.AudioTranscriptions
{
Expand All @@ -23,54 +24,111 @@ private static async ValueTask<AudioTranscription> TryCatch(
}
catch (NullAudioTranscriptionException nullAudioTranscriptionException)
{
throw new AudioTranscriptionValidationException(nullAudioTranscriptionException);
throw CreateAudioTranscriptionValidationException(
nullAudioTranscriptionException);
}
catch (InvalidAudioTranscriptionException invalidAudioTranscriptionException)
{
throw new AudioTranscriptionValidationException(invalidAudioTranscriptionException);
throw CreateAudioTranscriptionValidationException(
invalidAudioTranscriptionException);
}
catch (HttpResponseUrlNotFoundException httpResponseUrlNotFoundException)
{
var invalidConfigurationAudioTranscriptionException =
new InvalidConfigurationAudioTranscriptionException(httpResponseUrlNotFoundException);
new InvalidConfigurationAudioTranscriptionException(
message: "Invalid audio transcription configuration error occurred, contact support.",
httpResponseUrlNotFoundException);

throw new AudioTranscriptionDependencyException(invalidConfigurationAudioTranscriptionException);
throw CreateAudioTranscriptionDependencyException(
invalidConfigurationAudioTranscriptionException);
}
catch (HttpResponseUnauthorizedException httpResponseUnauthorizedException)
{
var unauthorizedAudioTranscriptionException =
new UnauthorizedAudioTranscriptionException(httpResponseUnauthorizedException);
new UnauthorizedAudioTranscriptionException(
message: "Unauthorized audio transcription request, fix errors and try again.",
httpResponseUnauthorizedException);

throw new AudioTranscriptionDependencyException(unauthorizedAudioTranscriptionException);
throw CreateAudioTranscriptionDependencyException(
unauthorizedAudioTranscriptionException);
}
catch (HttpResponseForbiddenException httpResponseForbiddenException)
{
var unauthorizedAudioTranscriptionException =
new UnauthorizedAudioTranscriptionException(httpResponseForbiddenException);
new UnauthorizedAudioTranscriptionException(
message: "Unauthorized audio transcription request, fix errors and try again.",
httpResponseForbiddenException);

throw new AudioTranscriptionDependencyException(unauthorizedAudioTranscriptionException);
throw CreateAudioTranscriptionDependencyException(
unauthorizedAudioTranscriptionException);
}
catch (HttpResponseBadRequestException httpResponseBadRequestException)
{
var invalidAudioTranscriptionException =
new InvalidAudioTranscriptionException(httpResponseBadRequestException);
new InvalidAudioTranscriptionException(
message: "Audio transcription is invalid.",
httpResponseBadRequestException);

throw new AudioTranscriptionDependencyValidationException(invalidAudioTranscriptionException);
throw CreateAudioTranscriptionDependencyValidationException(
invalidAudioTranscriptionException);
}
catch (HttpResponseTooManyRequestsException httpResponseTooManyRequestsException)
{
var excessiveCallAudioTranscriptionException =
new ExcessiveCallAudioTranscriptionException(httpResponseTooManyRequestsException);
new ExcessiveCallAudioTranscriptionException(
message: "Excessive call error occurred, limit your calls.",
httpResponseTooManyRequestsException);

throw new AudioTranscriptionDependencyValidationException(excessiveCallAudioTranscriptionException);
throw CreateAudioTranscriptionDependencyValidationException(
excessiveCallAudioTranscriptionException);
}
catch (Exception exception)
{
var failedAudioTranscriptionServiceException =
new FailedAudioTranscriptionServiceException(exception);
new FailedAudioTranscriptionServiceException(
message: "Failed Audio Transcription Service Exception occurred," +
" please contact support for assistance.",
exception);

throw new AudioTranscriptionServiceException(failedAudioTranscriptionServiceException);
throw CreateAudioTranscriptionServiceException(
failedAudioTranscriptionServiceException);
}
}

private static AudioTranscriptionValidationException
CreateAudioTranscriptionValidationException(Xeption innerException)
{

return new AudioTranscriptionValidationException(
message: "Audio transcription validation error occurred, fix errors and try again.",
innerException);
}

private static AudioTranscriptionDependencyException
CreateAudioTranscriptionDependencyException(Xeption innerException)
{

return new AudioTranscriptionDependencyException(
message: "Audio transcription dependency error occurred, contact support.",
innerException);
}

private static AudioTranscriptionDependencyValidationException
CreateAudioTranscriptionDependencyValidationException(Xeption innerException)
{

return new AudioTranscriptionDependencyValidationException(
message: "Chat completion dependency validation error occurred, fix errors and try again.",
innerException);
}

private static AudioTranscriptionServiceException
CreateAudioTranscriptionServiceException(Xeption innerException)
{

return new AudioTranscriptionServiceException(
message: "Audio transcription service error occurred, contact support.",
innerException);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ private static void ValidateAudioTranscriptionIsNotNull(AudioTranscription audio
{
if (audioTranscription is null)
{
throw new NullAudioTranscriptionException();
throw new NullAudioTranscriptionException(
message: "Audio transcription is null.");
}
}

Expand All @@ -48,7 +49,9 @@ private static void ValidateAudioTranscriptionIsNotNull(AudioTranscription audio

private static void Validate(params (dynamic Rule, string Parameter)[] validations)
{
InvalidAudioTranscriptionException invalidAudioTranscriptionException = new InvalidAudioTranscriptionException();
InvalidAudioTranscriptionException invalidAudioTranscriptionException =
new InvalidAudioTranscriptionException(
message: "Audio transcription is invalid.");

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

0 comments on commit 625e735

Please sign in to comment.