Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/main/client/AstClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {logger} from '../wrapper/loggerConfig';
import * as fs from 'fs';
import {finished} from 'stream/promises';
import {Client} from "./Client";
import {CxError} from "../errors/CxError";

export class AstClient {
private client: Client;
Expand All @@ -20,10 +21,9 @@ export class AstClient {
logger.info(`Download completed successfully. File saved to: ${outputPath}`);
} catch (error) {
logger.error(`Error downloading file from ${url}: ${error.message || error}`);
throw error;
throw new CxError(error.message || error);
} finally {
writer.close();
logger.info('Write stream closed.');
}
}
}
4 changes: 4 additions & 0 deletions src/main/client/HttpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {Client} from "./Client";

export class HttpClient implements Client {
private readonly axiosConfig: AxiosRequestConfig;
private readonly domainErrMsg = 'Unable to download the CLI from the URL. Try adding the domain: \'download.checkmarx.com\' to your allow list.';

constructor() {
this.axiosConfig = {
Expand Down Expand Up @@ -45,6 +46,9 @@ export class HttpClient implements Client {
return response;
} catch (error) {
logger.error(`Error sending ${method} request to ${url}: ${error.message || error}`);
if (this.axiosConfig.proxy!==undefined) {
throw new Error(`${this.domainErrMsg} \nError: ${error.message || error}`);
}
throw error;
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/main/errors/CxError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export class CxError extends Error {
constructor(message: string) {
super(message);
this.name = "CxError";
}
}
6 changes: 5 additions & 1 deletion src/main/osinstaller/CxInstaller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as tar from 'tar';
import * as unzipper from 'unzipper';
import {logger} from "../wrapper/loggerConfig";
import {AstClient} from "../client/AstClient";
import {CxError} from "../errors/CxError";

const linuxOS = 'linux';
const macOS = 'darwin';
Expand Down Expand Up @@ -41,7 +42,7 @@ export class CxInstaller {
const platformData = CxInstaller.PLATFORMS[this.platform];

if (!platformData) {
throw new Error('Unsupported platform or architecture');
throw new CxError('Unsupported platform or architecture');
}

const architecture = this.getArchitecture();
Expand Down Expand Up @@ -103,6 +104,9 @@ export class CxInstaller {
logger.info('Extracted CLI to:', this.resourceDirPath);
} catch (error) {
logger.error('Error during installation:', error);
if (error instanceof CxError) {
process.exit(1);
}
}
}

Expand Down