Skip to content
This repository was archived by the owner on Apr 1, 2025. It is now read-only.

Commit c889591

Browse files
authored
Merge pull request #42 from AssemblyAI/fern-bot/08-11-2024-1119PM
🌿 Fern Regeneration -- August 11, 2024
2 parents 49d0c93 + ad91d11 commit c889591

File tree

5 files changed

+36
-19
lines changed

5 files changed

+36
-19
lines changed

src/AssemblyAI/Core/Public/ApiException.cs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
using System.Text.Json;
2+
using AssemblyAI.Core;
3+
14
namespace AssemblyAI;
25

36
/// <summary>
47
/// This exception type will be thrown for any non-2XX API responses.
58
/// </summary>
69
public class ApiException(string message, int statusCode, object body)
7-
: AssemblyAIException(body is Error error ? error.Error_ : message)
10+
: AssemblyAIException(GetMessageFromJsonBody(message, body))
811
{
912
/// <summary>
1013
/// The error code of the response that triggered the exception.
@@ -15,4 +18,18 @@ public class ApiException(string message, int statusCode, object body)
1518
/// The body of the response that triggered the exception.
1619
/// </summary>
1720
internal object Body { get; } = body;
18-
}
21+
22+
private static string GetMessageFromJsonBody(string message, object body)
23+
{
24+
if (body is not string stringBody) return message;
25+
try
26+
{
27+
var errorObject = JsonUtils.Deserialize<Error>(stringBody);
28+
return errorObject.Error_;
29+
}
30+
catch (JsonException)
31+
{
32+
return stringBody;
33+
}
34+
}
35+
}

src/AssemblyAI/Files/FilesClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public async Task<UploadedFile> UploadAsync(Stream request, RequestOptions? opti
4747
throw new ApiException(
4848
$"Error with status code {response.StatusCode}",
4949
response.StatusCode,
50-
JsonUtils.Deserialize<object>(responseBody)
50+
responseBody
5151
);
5252
}
5353
}

src/AssemblyAI/Lemur/LemurClient.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public async Task<LemurTaskResponse> TaskAsync(
5151
throw new ApiException(
5252
$"Error with status code {response.StatusCode}",
5353
response.StatusCode,
54-
JsonUtils.Deserialize<object>(responseBody)
54+
responseBody
5555
);
5656
}
5757

@@ -90,7 +90,7 @@ public async Task<LemurSummaryResponse> SummaryAsync(
9090
throw new ApiException(
9191
$"Error with status code {response.StatusCode}",
9292
response.StatusCode,
93-
JsonUtils.Deserialize<object>(responseBody)
93+
responseBody
9494
);
9595
}
9696

@@ -129,7 +129,7 @@ public async Task<LemurQuestionAnswerResponse> QuestionAnswerAsync(
129129
throw new ApiException(
130130
$"Error with status code {response.StatusCode}",
131131
response.StatusCode,
132-
JsonUtils.Deserialize<object>(responseBody)
132+
responseBody
133133
);
134134
}
135135

@@ -167,7 +167,7 @@ public async Task<LemurActionItemsResponse> ActionItemsAsync(
167167
throw new ApiException(
168168
$"Error with status code {response.StatusCode}",
169169
response.StatusCode,
170-
JsonUtils.Deserialize<object>(responseBody)
170+
responseBody
171171
);
172172
}
173173

@@ -206,7 +206,7 @@ public async Task<OneOf<LemurStringResponse, LemurQuestionAnswerResponse>> GetRe
206206
throw new ApiException(
207207
$"Error with status code {response.StatusCode}",
208208
response.StatusCode,
209-
JsonUtils.Deserialize<object>(responseBody)
209+
responseBody
210210
);
211211
}
212212

@@ -244,7 +244,7 @@ public async Task<PurgeLemurRequestDataResponse> PurgeRequestDataAsync(
244244
throw new ApiException(
245245
$"Error with status code {response.StatusCode}",
246246
response.StatusCode,
247-
JsonUtils.Deserialize<object>(responseBody)
247+
responseBody
248248
);
249249
}
250250
}

src/AssemblyAI/Realtime/RealtimeClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public async Task<RealtimeTemporaryTokenResponse> CreateTemporaryTokenAsync(
5050
throw new ApiException(
5151
$"Error with status code {response.StatusCode}",
5252
response.StatusCode,
53-
JsonUtils.Deserialize<object>(responseBody)
53+
responseBody
5454
);
5555
}
5656
}

src/AssemblyAI/Transcripts/TranscriptsClient.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public async Task<TranscriptList> ListAsync(
7676
throw new ApiException(
7777
$"Error with status code {response.StatusCode}",
7878
response.StatusCode,
79-
JsonUtils.Deserialize<object>(responseBody)
79+
responseBody
8080
);
8181
}
8282

@@ -114,7 +114,7 @@ public async Task<Transcript> SubmitAsync(
114114
throw new ApiException(
115115
$"Error with status code {response.StatusCode}",
116116
response.StatusCode,
117-
JsonUtils.Deserialize<object>(responseBody)
117+
responseBody
118118
);
119119
}
120120

@@ -148,7 +148,7 @@ public async Task<Transcript> GetAsync(string transcriptId, RequestOptions? opti
148148
throw new ApiException(
149149
$"Error with status code {response.StatusCode}",
150150
response.StatusCode,
151-
JsonUtils.Deserialize<object>(responseBody)
151+
responseBody
152152
);
153153
}
154154

@@ -183,7 +183,7 @@ public async Task<Transcript> DeleteAsync(string transcriptId, RequestOptions? o
183183
throw new ApiException(
184184
$"Error with status code {response.StatusCode}",
185185
response.StatusCode,
186-
JsonUtils.Deserialize<object>(responseBody)
186+
responseBody
187187
);
188188
}
189189

@@ -221,7 +221,7 @@ public async Task<string> GetSubtitlesAsync(
221221
throw new ApiException(
222222
$"Error with status code {response.StatusCode}",
223223
response.StatusCode,
224-
JsonUtils.Deserialize<object>(responseBody)
224+
responseBody
225225
);
226226
}
227227

@@ -258,7 +258,7 @@ public async Task<SentencesResponse> GetSentencesAsync(
258258
throw new ApiException(
259259
$"Error with status code {response.StatusCode}",
260260
response.StatusCode,
261-
JsonUtils.Deserialize<object>(responseBody)
261+
responseBody
262262
);
263263
}
264264

@@ -295,7 +295,7 @@ public async Task<ParagraphsResponse> GetParagraphsAsync(
295295
throw new ApiException(
296296
$"Error with status code {response.StatusCode}",
297297
response.StatusCode,
298-
JsonUtils.Deserialize<object>(responseBody)
298+
responseBody
299299
);
300300
}
301301

@@ -336,7 +336,7 @@ public async Task<WordSearchResponse> WordSearchAsync(
336336
throw new ApiException(
337337
$"Error with status code {response.StatusCode}",
338338
response.StatusCode,
339-
JsonUtils.Deserialize<object>(responseBody)
339+
responseBody
340340
);
341341
}
342342

@@ -373,7 +373,7 @@ public async Task<RedactedAudioResponse> GetRedactedAudioAsync(
373373
throw new ApiException(
374374
$"Error with status code {response.StatusCode}",
375375
response.StatusCode,
376-
JsonUtils.Deserialize<object>(responseBody)
376+
responseBody
377377
);
378378
}
379379
}

0 commit comments

Comments
 (0)