peterszombati / xapi-node

xStation5 Trading API for NodeJS/JS
https://peterszombati.github.io/xapi-node/
Other
58 stars 19 forks source link

onReject not called when host is unreachable #11

Closed black-hawk85 closed 3 years ago

black-hawk85 commented 3 years ago

Hey, it's friday evening and xStation is closed due to maintenance, so the API is unreachable.

Just tried to get my balance via xapi-node but my Promise will never get resolved or rejected as connector.onReady or connector.onReject is never called. I would expect connector.onReject should be called in this case or do you have any other callback for this case?

I think you should be able to reproduce this by setting options.host to any unknown host.

peterszombati commented 3 years ago

Hey, this issue to be solved need development for create a new listener for connection troubles, but if you make a request it will reject if timeouted

peterszombati commented 3 years ago

keep open this issue

black-hawk85 commented 3 years ago

Hey,

yesterday while maintenance I tried making http request with axios.

var axios = require('axios')

axios.get("http://" + this.connector.account.host).then(res => {
  console.log(res)
}).catch(e => {
  console.log(e.response.status)
})

I always get status 403 no matter if system is online or offline.

There must be a solution from WebSocket side.

peterszombati commented 3 years ago

@black-hawk85 this API is only works through WebSocket

black-hawk85 commented 3 years ago

Ya I thought so. But I had the hope that their host will be down. Is there a possibility to ping the host through your WS connection before I start waiting for onReady?

peterszombati commented 3 years ago

@black-hawk85 for a fast solution I think you can just do a connection timeout, so if its not connected in 10 sec you can just handle it as the service is down, you can create function for it

peterszombati commented 3 years ago

@black-hawk85 I solved this issue by: now you can add timeout parameter to connection function