Skip to content

Commit

Permalink
Exchange.js print() + eslint edits
Browse files Browse the repository at this point in the history
  • Loading branch information
kroitor committed Mar 27, 2020
1 parent d7524b6 commit 1bd37cf
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions js/base/Exchange.js
Original file line number Diff line number Diff line change
Expand Up @@ -462,42 +462,50 @@ module.exports = class Exchange {
}
}

print (... args) {
console.log (... args)
}

fetch (url, method = 'GET', headers = undefined, body = undefined) {

if (isNode && this.userAgent) {
if (typeof this.userAgent === 'string')
if (typeof this.userAgent === 'string') {
headers = extend ({ 'User-Agent': this.userAgent }, headers)
else if ((typeof this.userAgent === 'object') && ('User-Agent' in this.userAgent))
} else if ((typeof this.userAgent === 'object') && ('User-Agent' in this.userAgent)) {
headers = extend (this.userAgent, headers)
}
}

if (typeof this.proxy === 'function') {

url = this.proxy (url)
if (isNode)
if (isNode) {
headers = extend ({ 'Origin': this.origin }, headers)
}

} else if (typeof this.proxy === 'string') {

if (this.proxy.length)
if (isNode)
headers = extend ({ 'Origin': this.origin }, headers)
if (this.proxy.length && isNode) {
headers = extend ({ 'Origin': this.origin }, headers)
}

url = this.proxy + url
}

headers = extend (this.headers, headers)

if (this.verbose)
console.log ("fetch:\n", this.id, method, url, "\nRequest:\n", headers, "\n", body, "\n")
if (this.verbose) {
this.print ("fetch:\n", this.id, method, url, "\nRequest:\n", headers, "\n", body, "\n")
}

return this.executeRestRequest (url, method, headers, body)
}

async fetch2 (path, type = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {

if (this.enableRateLimit)
if (this.enableRateLimit) {
await this.throttle (this.rateLimit)
}

const request = this.sign (path, type, method, params, headers, body)
return this.fetch (request.url, request.method, request.headers, request.body)
Expand Down Expand Up @@ -612,8 +620,9 @@ module.exports = class Exchange {
this.last_json_response = json // FIXME: for those classes that haven't switched to handleErrors yet
}

if (this.verbose)
console.log ("handleRestResponse:\n", this.id, method, url, response.status, response.statusText, "\nResponse:\n", responseHeaders, "\n", responseBody, "\n")
if (this.verbose) {
this.print ("handleRestResponse:\n", this.id, method, url, response.status, response.statusText, "\nResponse:\n", responseHeaders, "\n", responseBody, "\n")
}

this.handleErrors (response.status, response.statusText, url, method, responseHeaders, responseBody, json, requestHeaders, requestBody)
this.defaultErrorHandler (response.status, response.statusText, url, method, responseHeaders, responseBody, json)
Expand Down

0 comments on commit 1bd37cf

Please sign in to comment.