From 81b08a85a8ac7a5bc4e6b36c629b418bcbc1f6c7 Mon Sep 17 00:00:00 2001 From: Martina Date: Wed, 26 May 2021 13:05:13 -0700 Subject: [PATCH] fixing api docs issues --- components/api-docs/v1/get-slate.js | 6 ++++++ components/api-docs/v1/get.js | 10 ++++++++-- components/api-docs/v2/get-slate.js | 6 ++++++ components/api-docs/v2/get-user.js | 6 ++++++ components/api-docs/v2/get.js | 18 ++++++++++++------ 5 files changed, 38 insertions(+), 8 deletions(-) diff --git a/components/api-docs/v1/get-slate.js b/components/api-docs/v1/get-slate.js index 1af27724..7f9295c6 100644 --- a/components/api-docs/v1/get-slate.js +++ b/components/api-docs/v1/get-slate.js @@ -19,6 +19,12 @@ const EXAMPLE_CODE_JS = ( if (!response) { console.log("No response"); + return; +} + +if (!response.ok) { + console.log(response.error); + return response.error; } const json = await response.json(); diff --git a/components/api-docs/v1/get.js b/components/api-docs/v1/get.js index b69f2848..83bf38c5 100644 --- a/components/api-docs/v1/get.js +++ b/components/api-docs/v1/get.js @@ -4,7 +4,7 @@ import * as System from "~/components/system"; import CodeBlock from "~/components/system/CodeBlock"; const EXAMPLE_CODE_JS = (key) => `const response = await fetch('https://slate.host/api/v1/get', { - method: 'POST', + method: 'GET', headers: { 'Content-Type': 'application/json', Authorization: 'Basic ${key}', @@ -16,6 +16,12 @@ const EXAMPLE_CODE_JS = (key) => `const response = await fetch('https://slate.ho if (!response) { console.log("No response"); + return; +} + +if (!response.ok) { + console.log(response.error); + return response.error; } const json = await response.json(); @@ -41,7 +47,7 @@ json = { } } -r = requests.post(url, headers=headers, json=json) +r = requests.get(url, headers=headers, json=json) print(JSON.dumps(r.json(), indent=2))`; diff --git a/components/api-docs/v2/get-slate.js b/components/api-docs/v2/get-slate.js index 9c48a476..ddc8379e 100644 --- a/components/api-docs/v2/get-slate.js +++ b/components/api-docs/v2/get-slate.js @@ -19,6 +19,12 @@ const EXAMPLE_CODE_JS = ( if (!response) { console.log("No response"); + return; +} + +if (!response.ok) { + console.log(response.error); + return response.error; } const json = await response.json(); diff --git a/components/api-docs/v2/get-user.js b/components/api-docs/v2/get-user.js index 5c18bc7d..cb530752 100644 --- a/components/api-docs/v2/get-user.js +++ b/components/api-docs/v2/get-user.js @@ -19,6 +19,12 @@ const EXAMPLE_CODE_JS = ( if (!response) { console.log("No response"); + return; +} + +if (!response.ok) { + console.log(response.error); + return response.error; } const json = await response.json(); diff --git a/components/api-docs/v2/get.js b/components/api-docs/v2/get.js index 2a2a4f53..823af304 100644 --- a/components/api-docs/v2/get.js +++ b/components/api-docs/v2/get.js @@ -4,7 +4,7 @@ import * as System from "~/components/system"; import CodeBlock from "~/components/system/CodeBlock"; const EXAMPLE_CODE_JS = (key) => `const response = await fetch('https://slate.host/api/v2/get', { - method: 'POST', + method: 'GET', headers: { 'Content-Type': 'application/json', Authorization: 'Basic ${key}', @@ -13,6 +13,12 @@ const EXAMPLE_CODE_JS = (key) => `const response = await fetch('https://slate.ho if (!response) { console.log("No response"); + return; +} + +if (!response.ok) { + console.log(response.error); + return response.error; } const json = await response.json(); @@ -32,7 +38,7 @@ headers = { "Authorization": "Basic ${key}", } -r = requests.post(url, headers=headers) +r = requests.get(url, headers=headers) print(JSON.dumps(r.json(), indent=2))`; @@ -51,10 +57,10 @@ const EXAMPLE_RESPONSE = ` filename: "door.jpg", ownerId: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", data: { - name: "Door", - size: 33676, - type: "image/jpeg", - blurhash: "U6BzILt700IADjWBx]oz00f6?bs:00Rj_Nt7", + name: "Door", + size: 33676, + type: "image/jpeg", + blurhash: "U6BzILt700IADjWBx]oz00f6?bs:00Rj_Nt7", }, }, ],