Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
90 changes: 90 additions & 0 deletions src/libs/Ideogram/Generated/Ideogram.Exceptions.g.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#nullable enable

namespace Ideogram
{
/// <summary>
/// Represents an exception thrown by the API.
/// </summary>
[global::System.Serializable]
public partial class ApiException : global::System.Exception
{
/// <summary>
/// The HTTP status code of the response.
/// </summary>
public global::System.Net.HttpStatusCode StatusCode { get; }
/// <summary>
/// The response body.
/// </summary>
public string? ResponseBody { get; set; }
/// <summary>
/// The response headers.
/// </summary>
public global::System.Collections.Generic.Dictionary<string, global::System.Collections.Generic.IEnumerable<string>>? ResponseHeaders { get; set; }
/// <summary>
/// Initializes a new instance of the <see cref="ApiException"/> class.
/// </summary>
public ApiException()
{
}

/// <summary>
/// Initializes a new instance of the <see cref="ApiException"/> class with a specified error message.
/// </summary>
/// <param name="message">The message that describes the error.</param>
/// <param name="statusCode">The HTTP status code of the response.</param>
public ApiException(string message, global::System.Net.HttpStatusCode statusCode) : base(message)
{
StatusCode = statusCode;
}

/// <summary>
/// Initializes a new instance of the <see cref="ApiException"/> class with a specified error message and a reference to the inner exception that is the cause of this exception.
/// </summary>
/// <param name="message">The error message that explains the reason for the exception.</param>
/// <param name="innerException">The exception that is the cause of the current exception, or a null reference if no inner exception is specified.</param>
/// <param name="statusCode">The HTTP status code of the response.</param>
public ApiException(string message, global::System.Exception innerException, global::System.Net.HttpStatusCode statusCode) : base(message, innerException)
{
StatusCode = statusCode;
}
}

/// <summary>
/// Represents an exception thrown by the API.
/// </summary>
/// <typeparam name="T"></typeparam>
[global::System.Serializable]
public partial class ApiException<T> : ApiException
{
/// <summary>
/// The response object.
/// </summary>
public T? ResponseObject { get; set; }

/// <summary>
/// Initializes a new instance of the <see cref="ApiException"/> class.
/// </summary>
public ApiException()
{
}

/// <summary>
/// Initializes a new instance of the <see cref="ApiException"/> class with a specified error message.
/// </summary>
/// <param name="message">The message that describes the error.</param>
/// <param name="statusCode">The HTTP status code of the response.</param>
public ApiException(string message, global::System.Net.HttpStatusCode statusCode) : base(message, statusCode)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="ApiException"/> class with a specified error message and a reference to the inner exception that is the cause of this exception.
/// </summary>
/// <param name="message">The error message that explains the reason for the exception.</param>
/// <param name="innerException">The exception that is the cause of the current exception, or a null reference if no inner exception is specified.</param>
/// <param name="statusCode">The HTTP status code of the response.</param>
public ApiException(string message, global::System.Exception innerException, global::System.Net.HttpStatusCode statusCode) : base(message, innerException, statusCode)
{
}
}
}
175 changes: 158 additions & 17 deletions src/libs/Ideogram/Generated/Ideogram.GenerateClient.PostEditImage.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ partial void ProcessPostEditImageResponseContent(
/// </summary>
/// <param name="request"></param>
/// <param name="cancellationToken">The token to cancel the operation with</param>
/// <exception cref="global::System.InvalidOperationException"></exception>
/// <exception cref="global::Ideogram.ApiException"></exception>
public async global::System.Threading.Tasks.Task<global::Ideogram.GenerateImageResponse> PostEditImageAsync(
global::Ideogram.EditImageRequest request,
global::System.Threading.CancellationToken cancellationToken = default)
Expand Down Expand Up @@ -120,30 +120,171 @@ partial void ProcessPostEditImageResponseContent(
ProcessPostEditImageResponse(
httpClient: HttpClient,
httpResponseMessage: __response);
//
if ((int)__response.StatusCode == 400)
{
string? __content_400 = null;
if (ReadResponseAsString)
{
__content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
}
else
{
var __contentStream_400 = await __response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
}

var __content = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
throw new global::Ideogram.ApiException(
message: __response.ReasonPhrase ?? string.Empty,
statusCode: __response.StatusCode)
{
ResponseBody = __content_400,
ResponseHeaders = global::System.Linq.Enumerable.ToDictionary(
__response.Headers,
h => h.Key,
h => h.Value),
};
}
//
if ((int)__response.StatusCode == 401)
{
string? __content_401 = null;
if (ReadResponseAsString)
{
__content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
}
else
{
var __contentStream_401 = await __response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
}

ProcessResponseContent(
client: HttpClient,
response: __response,
content: ref __content);
ProcessPostEditImageResponseContent(
httpClient: HttpClient,
httpResponseMessage: __response,
content: ref __content);
throw new global::Ideogram.ApiException(
message: __response.ReasonPhrase ?? string.Empty,
statusCode: __response.StatusCode)
{
ResponseBody = __content_401,
ResponseHeaders = global::System.Linq.Enumerable.ToDictionary(
__response.Headers,
h => h.Key,
h => h.Value),
};
}
// Prompt or Initial Image failed the safety checks.
if ((int)__response.StatusCode == 422)
{
string? __content_422 = null;
global::Ideogram.GenerateImageSafetyError? __value_422 = null;
if (ReadResponseAsString)
{
__content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
__value_422 = global::Ideogram.GenerateImageSafetyError.FromJson(__content_422, JsonSerializerContext);
}
else
{
var __contentStream_422 = await __response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
__value_422 = await global::Ideogram.GenerateImageSafetyError.FromJsonStreamAsync(__contentStream_422, JsonSerializerContext).ConfigureAwait(false);
}

try
throw new global::Ideogram.ApiException<global::Ideogram.GenerateImageSafetyError>(
message: __response.ReasonPhrase ?? string.Empty,
statusCode: __response.StatusCode)
{
ResponseBody = __content_422,
ResponseObject = __value_422,
ResponseHeaders = global::System.Linq.Enumerable.ToDictionary(
__response.Headers,
h => h.Key,
h => h.Value),
};
}
//
if ((int)__response.StatusCode == 429)
{
__response.EnsureSuccessStatusCode();
string? __content_429 = null;
if (ReadResponseAsString)
{
__content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
}
else
{
var __contentStream_429 = await __response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
}

throw new global::Ideogram.ApiException(
message: __response.ReasonPhrase ?? string.Empty,
statusCode: __response.StatusCode)
{
ResponseBody = __content_429,
ResponseHeaders = global::System.Linq.Enumerable.ToDictionary(
__response.Headers,
h => h.Key,
h => h.Value),
};
}
catch (global::System.Net.Http.HttpRequestException __ex)

if (ReadResponseAsString)
{
throw new global::System.InvalidOperationException(__content, __ex);
var __content = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);

ProcessResponseContent(
client: HttpClient,
response: __response,
content: ref __content);
ProcessPostEditImageResponseContent(
httpClient: HttpClient,
httpResponseMessage: __response,
content: ref __content);

try
{
__response.EnsureSuccessStatusCode();
}
catch (global::System.Net.Http.HttpRequestException __ex)
{
throw new global::Ideogram.ApiException(
message: __content ?? __response.ReasonPhrase ?? string.Empty,
innerException: __ex,
statusCode: __response.StatusCode)
{
ResponseBody = __content,
ResponseHeaders = global::System.Linq.Enumerable.ToDictionary(
__response.Headers,
h => h.Key,
h => h.Value),
};
}

return
global::Ideogram.GenerateImageResponse.FromJson(__content, JsonSerializerContext) ??
throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" ");
}
else
{
try
{
__response.EnsureSuccessStatusCode();
}
catch (global::System.Net.Http.HttpRequestException __ex)
{
throw new global::Ideogram.ApiException(
message: __response.ReasonPhrase ?? string.Empty,
innerException: __ex,
statusCode: __response.StatusCode)
{
ResponseHeaders = global::System.Linq.Enumerable.ToDictionary(
__response.Headers,
h => h.Key,
h => h.Value),
};
}

using var __responseStream = await __response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);

return
global::Ideogram.GenerateImageResponse.FromJson(__content, JsonSerializerContext) ??
throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" ");
var __responseValue = await global::Ideogram.GenerateImageResponse.FromJsonStreamAsync(__responseStream, JsonSerializerContext).ConfigureAwait(false);

return
__responseValue ??
throw new global::System.InvalidOperationException("Response deserialization failed.");
}
}

/// <summary>
Expand Down
Loading