@@ -30,7 +30,7 @@ partial void ProcessPostEditImageResponseContent(
3030 /// </summary>
3131 /// <param name="request"></param>
3232 /// <param name="cancellationToken">The token to cancel the operation with</param>
33- /// <exception cref="global::System.InvalidOperationException "></exception>
33+ /// <exception cref="global::Ideogram.ApiException "></exception>
3434 public async global ::System . Threading . Tasks . Task < global ::Ideogram . GenerateImageResponse > PostEditImageAsync (
3535 global ::Ideogram . EditImageRequest request ,
3636 global ::System . Threading . CancellationToken cancellationToken = default )
@@ -120,30 +120,171 @@ partial void ProcessPostEditImageResponseContent(
120120 ProcessPostEditImageResponse (
121121 httpClient : HttpClient ,
122122 httpResponseMessage : __response ) ;
123+ //
124+ if ( ( int ) __response . StatusCode == 400 )
125+ {
126+ string ? __content_400 = null ;
127+ if ( ReadResponseAsString )
128+ {
129+ __content_400 = await __response . Content . ReadAsStringAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
130+ }
131+ else
132+ {
133+ var __contentStream_400 = await __response . Content . ReadAsStreamAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
134+ }
123135
124- var __content = await __response . Content . ReadAsStringAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
136+ throw new global ::Ideogram . ApiException (
137+ message : __response . ReasonPhrase ?? string . Empty ,
138+ statusCode : __response . StatusCode )
139+ {
140+ ResponseBody = __content_400 ,
141+ ResponseHeaders = global ::System . Linq . Enumerable . ToDictionary (
142+ __response . Headers ,
143+ h => h . Key ,
144+ h => h . Value ) ,
145+ } ;
146+ }
147+ //
148+ if ( ( int ) __response . StatusCode == 401 )
149+ {
150+ string ? __content_401 = null ;
151+ if ( ReadResponseAsString )
152+ {
153+ __content_401 = await __response . Content . ReadAsStringAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
154+ }
155+ else
156+ {
157+ var __contentStream_401 = await __response . Content . ReadAsStreamAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
158+ }
125159
126- ProcessResponseContent (
127- client : HttpClient ,
128- response : __response ,
129- content : ref __content ) ;
130- ProcessPostEditImageResponseContent (
131- httpClient : HttpClient ,
132- httpResponseMessage : __response ,
133- content : ref __content ) ;
160+ throw new global ::Ideogram . ApiException (
161+ message : __response . ReasonPhrase ?? string . Empty ,
162+ statusCode : __response . StatusCode )
163+ {
164+ ResponseBody = __content_401 ,
165+ ResponseHeaders = global ::System . Linq . Enumerable . ToDictionary (
166+ __response . Headers ,
167+ h => h . Key ,
168+ h => h . Value ) ,
169+ } ;
170+ }
171+ // Prompt or Initial Image failed the safety checks.
172+ if ( ( int ) __response . StatusCode == 422 )
173+ {
174+ string ? __content_422 = null ;
175+ global ::Ideogram . GenerateImageSafetyError ? __value_422 = null ;
176+ if ( ReadResponseAsString )
177+ {
178+ __content_422 = await __response . Content . ReadAsStringAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
179+ __value_422 = global ::Ideogram . GenerateImageSafetyError . FromJson ( __content_422 , JsonSerializerContext ) ;
180+ }
181+ else
182+ {
183+ var __contentStream_422 = await __response . Content . ReadAsStreamAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
184+ __value_422 = await global ::Ideogram . GenerateImageSafetyError . FromJsonStreamAsync ( __contentStream_422 , JsonSerializerContext ) . ConfigureAwait ( false ) ;
185+ }
134186
135- try
187+ throw new global ::Ideogram . ApiException < global ::Ideogram . GenerateImageSafetyError > (
188+ message : __response . ReasonPhrase ?? string . Empty ,
189+ statusCode : __response . StatusCode )
190+ {
191+ ResponseBody = __content_422 ,
192+ ResponseObject = __value_422 ,
193+ ResponseHeaders = global ::System . Linq . Enumerable . ToDictionary (
194+ __response . Headers ,
195+ h => h . Key ,
196+ h => h . Value ) ,
197+ } ;
198+ }
199+ //
200+ if ( ( int ) __response . StatusCode == 429 )
136201 {
137- __response . EnsureSuccessStatusCode ( ) ;
202+ string ? __content_429 = null ;
203+ if ( ReadResponseAsString )
204+ {
205+ __content_429 = await __response . Content . ReadAsStringAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
206+ }
207+ else
208+ {
209+ var __contentStream_429 = await __response . Content . ReadAsStreamAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
210+ }
211+
212+ throw new global ::Ideogram . ApiException (
213+ message : __response . ReasonPhrase ?? string . Empty ,
214+ statusCode : __response . StatusCode )
215+ {
216+ ResponseBody = __content_429 ,
217+ ResponseHeaders = global ::System . Linq . Enumerable . ToDictionary (
218+ __response . Headers ,
219+ h => h . Key ,
220+ h => h . Value ) ,
221+ } ;
138222 }
139- catch ( global ::System . Net . Http . HttpRequestException __ex )
223+
224+ if ( ReadResponseAsString )
140225 {
141- throw new global ::System . InvalidOperationException ( __content , __ex ) ;
226+ var __content = await __response . Content . ReadAsStringAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
227+
228+ ProcessResponseContent (
229+ client : HttpClient ,
230+ response : __response ,
231+ content : ref __content ) ;
232+ ProcessPostEditImageResponseContent (
233+ httpClient : HttpClient ,
234+ httpResponseMessage : __response ,
235+ content : ref __content ) ;
236+
237+ try
238+ {
239+ __response . EnsureSuccessStatusCode ( ) ;
240+ }
241+ catch ( global ::System . Net . Http . HttpRequestException __ex )
242+ {
243+ throw new global ::Ideogram . ApiException (
244+ message : __content ?? __response . ReasonPhrase ?? string . Empty ,
245+ innerException : __ex ,
246+ statusCode : __response . StatusCode )
247+ {
248+ ResponseBody = __content ,
249+ ResponseHeaders = global ::System . Linq . Enumerable . ToDictionary (
250+ __response . Headers ,
251+ h => h . Key ,
252+ h => h . Value ) ,
253+ } ;
254+ }
255+
256+ return
257+ global ::Ideogram . GenerateImageResponse . FromJson ( __content , JsonSerializerContext ) ??
258+ throw new global ::System . InvalidOperationException ( $ "Response deserialization failed for \" { __content } \" ") ;
142259 }
260+ else
261+ {
262+ try
263+ {
264+ __response . EnsureSuccessStatusCode ( ) ;
265+ }
266+ catch ( global ::System . Net . Http . HttpRequestException __ex )
267+ {
268+ throw new global ::Ideogram . ApiException (
269+ message : __response . ReasonPhrase ?? string . Empty ,
270+ innerException : __ex ,
271+ statusCode : __response . StatusCode )
272+ {
273+ ResponseHeaders = global ::System . Linq . Enumerable . ToDictionary (
274+ __response . Headers ,
275+ h => h . Key ,
276+ h => h . Value ) ,
277+ } ;
278+ }
279+
280+ using var __responseStream = await __response . Content . ReadAsStreamAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
143281
144- return
145- global ::Ideogram . GenerateImageResponse . FromJson ( __content , JsonSerializerContext ) ??
146- throw new global ::System . InvalidOperationException ( $ "Response deserialization failed for \" { __content } \" ") ;
282+ var __responseValue = await global ::Ideogram . GenerateImageResponse . FromJsonStreamAsync ( __responseStream , JsonSerializerContext ) . ConfigureAwait ( false ) ;
283+
284+ return
285+ __responseValue ??
286+ throw new global ::System . InvalidOperationException ( "Response deserialization failed." ) ;
287+ }
147288 }
148289
149290 /// <summary>
0 commit comments