Skip to content

Commit

Permalink
Fix paas:logs errors not displaying (#187)
Browse files Browse the repository at this point in the history
* fix: log errors when unable to retrieve PaaS application logs
  • Loading branch information
Kuruyia authored Jun 27, 2023
1 parent e31faff commit c4424a5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
25 changes: 25 additions & 0 deletions src/commands/paas/logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,31 @@ class PaasLogs extends PaasKommand {
until,
});

// Don't continue if an error occurred
if (incomingMessage.statusCode !== 200) {
return new Promise<void>((_, reject) => {
// Collect the whole response body
let responseBody = "";

incomingMessage.on("data", (buffer) => {
responseBody += buffer.toString();
});

incomingMessage.on("end", () => {
let response;

try {
response = JSON.parse(responseBody);
} catch (error: any) {
reject(new Error("An error occurred while parsing the error response body from Kuzzle"));
return;
}

reject(response.error);
});
});
}

// Read the response line by line
const lineStream = readline.createInterface({
input: incomingMessage,
Expand Down
5 changes: 4 additions & 1 deletion src/support/kuzzle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,10 @@ export class KuzzleSDK {
const options = {
method: "POST",
headers: {
"Authorization": `Bearer ${this.sdk.jwt}`,
Accept: "application/json",
"Accept-Encoding": "identity",
Authorization: `Bearer ${this.sdk.jwt}`,
Connection: "keep-alive",
"Content-Length": Buffer.byteLength(body),
"Content-Type": "application/json",
},
Expand Down

0 comments on commit c4424a5

Please sign in to comment.