Skip to content
Permalink
Browse files

Handle Errors

  • Loading branch information...
piavgh committed Feb 15, 2019
1 parent dd9f092 commit 2833bbdf2e49487db83b28f3c4d67a0ef8ff3798
Showing with 35 additions and 2 deletions.
  1. +3 −0 cron/index.js
  2. +1 −0 services/coinmarketcap/getMarketQuotes.js
  3. +17 −1 services/getOrderBook.js
  4. +14 −1 utils/socket.js
@@ -9,6 +9,9 @@ import { defaultOrderParams } from '../config'
const runMarketMaker = async () => {
try {
const orderBookData = await getOrderBook()
if (!orderBookData) {
return
}

if (orderBookData.bids.length === 0) {
return await handleEmptyOrderbook('BUY')
@@ -4,6 +4,7 @@ import { coinMarketCapAPI } from "../../config"

export const getMarketQuotes = async (baseTokenSymbol = null, quoteTokenSymbol = null) => {
try {
console.log('Fetch data from coinmarketcap.com')
baseTokenSymbol = baseTokenSymbol || 'ETH'
quoteTokenSymbol = quoteTokenSymbol || 'TOMO'

@@ -11,7 +11,23 @@ export const getOrderBook = async (baseToken = null, quoteToken = null) => {

return response.data.data
} catch (err) {
console.log(err)
if (err.response) {
// The request was made and the server responded with a status code
// that falls out of the range of 2xx
console.log(err.response.data)
console.log(err.response.status)
console.log(err.response.headers)
} else if (err.request) {
// The request was made but no response was received
// `error.request` is an instance of XMLHttpRequest in the browser and an instance of
// http.ClientRequest in node.js
// console.log(err.request)
console.log('getOrderBook was made but no response was received')
} else {
// Something happened in setting up the request that triggered an Error
console.log('Error', err.message)
}

return null
}
}
@@ -8,6 +8,19 @@ ws.on('open', function open() {
console.log('Connected to Websocket')
})

ws.on('error', (err) => {
console.log('Connection error')
console.log(err)
})

export const sendToServer = (message) => {
ws.send(JSON.stringify(message))
try {
ws.send(JSON.stringify(message), function ack(err) {
if (err) {
console.log(err)
}
})
} catch (err) {
console.log(err)
}
}

0 comments on commit 2833bbd

Please sign in to comment.
You can’t perform that action at this time.