Island UI: fix a bug in IslandHttpClient.tsx that caused the body of a Response object to be a promise instead of an object

This commit is contained in:
VakarisZ 2021-07-15 10:05:25 +03:00
parent 5743f8ea98
commit 980f06ed73
1 changed files with 6 additions and 2 deletions

View File

@ -13,18 +13,22 @@ export class Response{
class IslandHttpClient extends AuthComponent { class IslandHttpClient extends AuthComponent {
post(endpoint: string, contents: any): Promise<Response>{ post(endpoint: string, contents: any): Promise<Response>{
let status = null;
return this.authFetch(endpoint, return this.authFetch(endpoint,
{ {
method: 'POST', method: 'POST',
headers: {'Content-Type': 'application/json'}, headers: {'Content-Type': 'application/json'},
body: JSON.stringify(contents) body: JSON.stringify(contents)
}) })
.then(res => new Response(res.json(), res.status)); .then(res => {status = res.status; return res.json()})
.then(res => new Response(res, status));
} }
get(endpoint: string): Promise<Response>{ get(endpoint: string): Promise<Response>{
let status = null;
return this.authFetch(endpoint) return this.authFetch(endpoint)
.then(res => new Response(res.json(), res.status)); .then(res => {status = res.status; return res.json()})
.then(res => new Response(res, status));
} }
} }