Skip to content

Commit 2481390

Browse files
authored
Merge pull request #167 from appwrite/fix-dotnet-json-parse
fix(dotnet): conditional json parse & non json tests
2 parents a669167 + c93160d commit 2481390

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

templates/dotnet/src/Appwrite/Client.cs.twig

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ using Newtonsoft.Json.Linq;
22
using System;
33
using System.Collections.Generic;
44
using System.IO;
5+
using System.Linq;
56
using System.Net;
67
using System.Net.Http;
78
using System.Net.Http.Headers;
@@ -165,7 +166,13 @@ namespace {{ spec.title | caseUcfirst }}
165166
var response = await httpResponseMessage.Content.ReadAsStringAsync();
166167

167168
if (code >= 400) {
168-
string message = (JObject.Parse(response))["message"].ToString();
169+
var message = response.ToString();
170+
var isJson = httpResponseMessage.Content.Headers.GetValues("Content-Type").FirstOrDefault().Contains("application/json");
171+
172+
if (isJson) {
173+
message = (JObject.Parse(message))["message"].ToString();
174+
}
175+
169176
throw new {{spec.title | caseUcfirst}}Exception(message, code, response.ToString());
170177
}
171178

tests/languages/dotnet/tests.ps1

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ Print-Response $response.GetResult()
6464
$response = $general.Upload("string", 123, $list, (Get-Item "../../../../resources/file.png")) | Await-Task
6565
Print-Response $response.GetResult()
6666

67+
try {
68+
$response = $general.Empty() | Await-Task
69+
$response.GetResult() | Out-Null
70+
} catch [Appwrite.AppwriteException] {
71+
Write-Host $_.Exception.Message
72+
}
73+
6774
try {
6875
$response = $general.Error400() | Await-Task
6976
$response.GetResult()
@@ -76,4 +83,11 @@ try {
7683
$response.GetResult()
7784
} catch [Appwrite.AppwriteException] {
7885
Write-Host $_.Exception.Message
86+
}
87+
88+
try {
89+
$response = $general.Error502() | Await-Task
90+
$response.GetResult()
91+
} catch [Appwrite.AppwriteException] {
92+
Write-Host $_.Exception.Message
7993
}

0 commit comments

Comments
 (0)