Last active
February 26, 2019 14:08
-
-
Save rabbishuki/489057f40579e89ba06af3702cd52e7b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sendToOtherNodeService = (url, bodyReq, timeout, callback) => { | |
try { | |
request({ | |
url: url, | |
method: 'POST', | |
json: true, | |
body: bodyReq, | |
timeout: timeOut, | |
}, (error, response, body) => { | |
if (error != null) { | |
cb({error: error || ''}); | |
} | |
} else { | |
try { | |
body = JSON.parse(body); | |
} catch (e) { | |
} | |
if (body) { | |
cb({response: body}); | |
} else { | |
cb({error: 'body empty'}); | |
} | |
} | |
}).on('error', function (e) { | |
cb({error: e}); | |
}); | |
} catch (e1) { | |
cb({error: e1}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment