jfrog / jfrog-client-js

Xray Javascript Client
Apache License 2.0
13 stars 16 forks source link

return false when I ping #15

Open Jerry4013 opened 3 years ago

Jerry4013 commented 3 years ago

Hi, I installed this package to test the rest API of XRAY, but after I follow the README, when I try the "ping" API, I got a false instead a "pong". Could you please help with this issue? Thank you!

`import {XrayClient} from 'xray-client-js'

let xrayClient = new XrayClient({ serverUrl: 'myurl', username: 'myusername', password: 'mypassword!', proxy: {host: 'myurl', port: 80, protocol: 'https'}, headers: { } });

xrayClient.system().ping() .then(result => { console.log(result); }) .catch(error => { console.error(error); });`

yahavi commented 3 years ago

@Jerry4013, Thanks for reporting this issue!

Pong returned only if the ping succeeded. False returned when there was an error. Here is the ping function: https://github.com/jfrog/xray-client-js/blob/master/src/SystemClient.ts#L10

try {
    return await this.httpClient.doRequest(requestParams);
} catch (error) {
    return false;
}

In order to support your use case and throw errors, we should remove the try-catch clause and modify the tests respectfully. Would you like to contribute code that removing the try-catch?

By the way, you can find in the tests many examples for ping commands: https://github.com/jfrog/xray-client-js/blob/master/test/SystemClient.spec.ts#L28.