1+ using Newtonsoft.Json.Linq;
12using System;
23using System.Collections.Generic;
34using System.IO;
@@ -11,22 +12,14 @@ namespace {{ spec.title | caseUcfirst }}
1112{
1213 public class Client
1314 {
14-
1515 private readonly HttpClient http;
16-
1716 private readonly Dictionary<string , string > headers;
18-
1917 private readonly Dictionary<string , string > config;
20-
2118 private string endPoint;
22-
2319 private bool selfSigned;
2420
25- CookieContainer cookieJar = new CookieContainer();
26-
2721 public Client() : this("https://appwrite.io/v1", false, new HttpClient())
2822 {
29-
3023 }
3124
3225 public Client(string endPoint, bool selfSigned, HttpClient http)
@@ -44,9 +37,7 @@ namespace {{ spec.title | caseUcfirst }}
4437
4538 };
4639 this.config = new Dictionary<string , string >();
47- this.http = http;
48-
49- // coockie container ??
40+ this.http = http;
5041 }
5142
5243 public Client SetSelfSigned(bool selfSigned)
@@ -71,10 +62,9 @@ namespace {{ spec.title | caseUcfirst }}
7162 return config;
7263 }
7364
74-
7565{% for header in spec .global .headers %}
7666{% if header .description %}
77- /// {{header .description }}
67+ /// < summary > {{header .description }}</ summary >
7868{% endif %}
7969 public Client Set{{header .key | caseUcfirst }}(string value) {
8070 config.Add("{{ header .key | caseCamel }}", value);
@@ -83,8 +73,6 @@ namespace {{ spec.title | caseUcfirst }}
8373 }
8474
8575{% endfor %}
86-
87-
8876 public Client AddHeader(String key, String value)
8977 {
9078 headers.Add(key, value);
@@ -106,8 +94,6 @@ namespace {{ spec.title | caseUcfirst }}
10694
10795 if ("multipart/form-data".Equals(headers["content-type"], StringComparison.InvariantCultureIgnoreCase))
10896 {
109-
110-
11197 MultipartFormDataContent form = new MultipartFormDataContent();
11298
11399 foreach (var parameter in parameters)
@@ -172,10 +158,24 @@ namespace {{ spec.title | caseUcfirst }}
172158 request.Headers.Add(header.Key, header.Value);
173159 }
174160 }
175- HttpResponseMessage httpResponseMessage = await http.SendAsync(request);
161+ try
162+ {
163+ var httpResponseMessage = await http.SendAsync(request);
164+ var code = (int) httpResponseMessage.StatusCode;
165+ var response = await httpResponseMessage.Content.ReadAsStringAsync();
176166
177- return httpResponseMessage;
178- }
167+ if (code >= 400) {
168+ string message = (JObject.Parse(response))["message"].ToString();
169+ throw new {{spec .title | caseUcfirst }}Exception(message, code, response.ToString());
170+ }
179171
172+ return httpResponseMessage;
173+ }
174+ catch (System.Exception e)
175+ {
176+ throw new {{spec .title | caseUcfirst }}Exception(e.Message, e);
177+ }
178+
179+ }
180180 }
181181}
0 commit comments