Skip to content

Commit 76820de

Browse files
committed
feat: warn response format
1 parent e32a6da commit 76820de

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

templates/node/src/client.ts.twig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ type Headers = {
1818
[key: string]: string;
1919
}
2020

21+
function greaterThan(v1, v2) {
22+
const [a, b, c] = v1.split('.').map(Number);
23+
const [x, y, z] = v2.split('.').map(Number);
24+
return a > x || a === x && (b > y || b === y && c > z);
25+
}
26+
2127
class {{spec.title | caseUcfirst}}Exception extends Error {
2228
code: number;
2329
response: string;
@@ -262,6 +268,12 @@ class Client {
262268

263269
const response = await fetch(uri, options);
264270

271+
const latestFormat = responseType.headers.get('x-appwrite-default-response-format');
272+
const sentFormat = headers['x-appwrite-response-format'];
273+
if (defaultFormat && sentFormat && greaterThan(sentFormat, defaultFormat)) {
274+
console.warn(`Request made with SDK version {{ sdk.version }} using response format ${sentFormat} while the server latest is ${defaultFormat}. This may lead to unexpected behavior. Please downgrade your SDK version to match the server default. {{ sdk.url}}
275+
}
276+
265277
if (response.headers.get('content-type')?.includes('application/json')) {
266278
data = await response.json();
267279
} else if (responseType === 'arrayBuffer') {

0 commit comments

Comments
 (0)