Skip to content

Commit

Permalink
#479: fixed calling remote procedures that not return any result
Browse files Browse the repository at this point in the history
  • Loading branch information
petermasking committed Feb 9, 2024
1 parent 01ae521 commit 4f39716
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions packages/runtime/src/services/Remote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ export default class Remote
body: JSON.stringify(segmentFiles)
};

const response = await this.#callRemote(url, options, 200);
const response = await this.#callRemote(url, options);

return response.text();
}

Expand All @@ -44,7 +45,7 @@ export default class Remote
const url = `${this.#url}/${filename}`;
const options = { method: 'GET' };

const response = await this.#callRemote(url, options, 200);
const response = await this.#callRemote(url, options);
const type = response.headers.get('Content-Type') || 'application/octet-stream';
const content = await response.text();

Expand All @@ -56,7 +57,7 @@ export default class Remote
const url = `${this.#url}/health/status`;
const options = { method: 'GET' };

const response = await this.#callRemote(url, options, 200);
const response = await this.#callRemote(url, options);
const healthy = await response.text();

return Boolean(healthy);
Expand All @@ -67,7 +68,7 @@ export default class Remote
const url = `${this.#url}/health`;
const options = { method: 'GET' };

const response = await this.#callRemote(url, options, 200);
const response = await this.#callRemote(url, options);
const health = await response.json();

return new Map(Object.entries(health));
Expand All @@ -89,7 +90,7 @@ export default class Remote
body: JSON.stringify(body)
};

await this.#callRemote(url, options, 201);
await this.#callRemote(url, options);
}

async run(request: Request): Promise<ResultResponse>
Expand All @@ -109,25 +110,30 @@ export default class Remote
body: body
};

const response = await this.#callRemote(url, options, 200);
const response = await this.#callRemote(url, options);
const result = await this.#createResponseResult(response);
const headers = this.#createResponseHeaders(response);

return new ResultResponse(result, headers);
}

async #callRemote(url: string, options: object, expectedStatus: number): Promise<Response>
async #callRemote(url: string, options: object): Promise<Response>
{
const response = await fetch(url, options);

if (response.status !== expectedStatus)
if (this.#isErrorResponse(response))
{
throw await this.#createResponseResult(response);
}

return response;
}

#isErrorResponse(response: Response): boolean
{
return response.status < 200 || response.status > 299;
}

async #createRequestBody(body: unknown): Promise<string>
{
const data = await this.#serializer.serialize(body);
Expand Down

0 comments on commit 4f39716

Please sign in to comment.