Skip to content

Commit 8a8e12f

Browse files
authored
Merge pull request #826 from appwrite/feat-warn-response-format
feat: warn response format
2 parents 0a66c11 + ee268fb commit 8a8e12f

File tree

15 files changed

+94
-0
lines changed

15 files changed

+94
-0
lines changed

templates/android/library/src/main/java/io/package/Client.kt.twig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,14 @@ class Client @JvmOverloads constructor(
473473
it.cancel(error)
474474
return
475475
}
476+
477+
val warnings = response.headers["x-{{ spec.title | lower }}-warning"]
478+
if (warnings != null) {
479+
warnings.split(";").forEach { warning ->
480+
println("Warning: $warning")
481+
}
482+
}
483+
476484
when {
477485
responseType == Boolean::class.java -> {
478486
it.resume(true as T)

templates/apple/Sources/Client.swift.twig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,12 @@ open class Client {
278278
timeout: .seconds(30)
279279
)
280280

281+
if let warning = response.headers["x-{{ spec.title | lower }}-warning"].first {
282+
warning.split(separator: ";").forEach { warning in
283+
print("Warning: \(warning)")
284+
}
285+
}
286+
281287
switch response.status.code {
282288
case 0..<400:
283289
if response.headers["Set-Cookie"].count > 0 {

templates/cli/lib/client.js.twig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ class Client {
132132
},
133133
}),
134134
});
135+
136+
const warnings = response.headers.get('x-{{ spec.title | lower }}-warning');
137+
if (warnings) {
138+
warnings.split(';').forEach((warning) => console.warn(warning));
139+
}
135140
} catch (error) {
136141
throw new {{spec.title | caseUcfirst}}Exception(error.message);
137142
}

templates/dart/lib/src/client_mixin.dart.twig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'package:http/http.dart' as http;
22
import 'exception.dart';
33
import 'response.dart';
44
import 'dart:convert';
5+
import 'dart:developer';
56
import 'enums.dart';
67

78
class ClientMixin {
@@ -67,6 +68,12 @@ class ClientMixin {
6768

6869
Response prepareResponse(http.Response res, {ResponseType? responseType}) {
6970
responseType ??= ResponseType.json;
71+
72+
String? warnings = res.headers['x-{{ spec.title | lower }}-warning'];
73+
if (warnings != null) {
74+
warnings.split(';').forEach((warning) => log('Warning: $warning'));
75+
}
76+
7077
if (res.statusCode >= 400) {
7178
if ((res.headers['content-type'] ?? '').contains('application/json')) {
7279
final response = json.decode(res.body);

templates/deno/src/client.ts.twig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ export class Client {
9696
headers,
9797
body
9898
});
99+
100+
const warnings = response.headers.get('x-{{ spec.title | lower }}-warning');
101+
if (warnings) {
102+
warnings.split(';').forEach((warning: string) => console.warn('Warning: ' + warning));
103+
}
99104
} catch (error) {
100105
throw new {{spec.title | caseUcfirst}}Exception(error.message);
101106
}

templates/dotnet/Package/Client.cs.twig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,14 @@ namespace {{ spec.title | caseUcfirst }}
269269
var response = await _http.SendAsync(request);
270270
var code = (int)response.StatusCode;
271271

272+
if (response.Headers.TryGetValues("x-{{ spec.title | lower }}-warning", out var warnings))
273+
{
274+
foreach (var warning in warnings)
275+
{
276+
Console.WriteLine("Warning: " + warning);
277+
}
278+
}
279+
272280
string contentType = string.Empty;
273281
if (response.Content.Headers.TryGetValues("Content-Type", out var contentTypes))
274282
{

templates/flutter/lib/src/client_mixin.dart.twig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'package:http/http.dart' as http;
22
import 'exception.dart';
33
import 'response.dart';
44
import 'dart:convert';
5+
import 'dart:developer';
56
import 'enums.dart';
67

78
class ClientMixin {
@@ -67,6 +68,12 @@ class ClientMixin {
6768

6869
Response prepareResponse(http.Response res, {ResponseType? responseType}) {
6970
responseType ??= ResponseType.json;
71+
72+
String? warnings = res.headers['x-{{ spec.title | lower }}-warning'];
73+
if (warnings != null) {
74+
warnings.split(';').forEach((warning) => log('Warning: $warning'));
75+
}
76+
7077
if (res.statusCode >= 400) {
7178
if ((res.headers['content-type'] ?? '').contains('application/json')) {
7279
final response = json.decode(res.body);

templates/kotlin/src/main/kotlin/io/appwrite/Client.kt.twig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,14 @@ class Client @JvmOverloads constructor(
523523
it.cancel(error)
524524
return
525525
}
526+
527+
val warnings = response.headers["x-{{ spec.title | lower }}-warning"]
528+
if (warnings != null) {
529+
warnings.split(";").forEach { warning ->
530+
println("Warning: $warning")
531+
}
532+
}
533+
526534
when {
527535
responseType == Boolean::class.java -> {
528536
it.resume(true as T)

templates/node/src/client.ts.twig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,11 @@ class Client {
262262

263263
const response = await fetch(uri, options);
264264

265+
const warnings = response.headers.get('x-{{ spec.title | lower }}-warning');
266+
if (warnings) {
267+
warnings.split(';').forEach((warning: string) => console.warn('Warning: ' + warning));
268+
}
269+
265270
if (response.headers.get('content-type')?.includes('application/json')) {
266271
data = await response.json();
267272
} else if (responseType === 'arrayBuffer') {

templates/php/src/Client.php.twig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,13 @@ class Client
176176
$responseBody = curl_exec($ch);
177177
$contentType = $responseHeaders['content-type'] ?? '';
178178
$responseStatus = curl_getinfo($ch, CURLINFO_HTTP_CODE);
179+
180+
$warnings = $responseHeaders['x-{{spec.title | caseLower}}-warning'] ?? '';
181+
if ($warnings) {
182+
foreach(explode(';', $warnings) as $warning) {
183+
echo 'Warning: ' . $warning . PHP_EOL;
184+
}
185+
}
179186
180187
switch(substr($contentType, 0, strpos($contentType, ';'))) {
181188
case 'application/json':

0 commit comments

Comments
 (0)