I'm using node-twilio and I keep getting a "Error: Unable to reach host: "api.twilio.com" for every request. We've checked the packets via mtr and they are reaching api.twilio.com. Running on debian on GCE.
After days of digging around, found out that the node-twilio module shows many errors incorrectly as:
"Error: Unable to reach host: "api.twilio.com".
The following lines:
var error = null;
if (err || (response && (response.statusCode < 200 || response.statusCode > 206))) {
error = {};
// response is null if server is unreachable
if (response) {
error.status = response.statusCode;
error.message = data ? data.message : 'Unable to complete HTTP request';
error.code = data && data.code;
error.moreInfo = data && data.more_info;
} else {
error.status = err.code;
error.message = 'Unable to reach host: "'+client.host+'"';
}
}
This happens because you have a self signed certificate in your chain and the underlying module twilio depends on is request, which is throwing the following error:
Error: SELF_SIGNED_CERT_IN_CHAIN but this is not the error being thrown by node-twilio (bad error propagation on their part)
There are 2 fixes:
1.Tell nodejs to ignore self signed certificates in chain by setting:
export NODE_TLS_REJECT_UNAUTHORIZED=0
Find the self signed certificate and remove it from the chain. Here is an example using openssl: https://serverfault.com/questions/590870/how-to-view-all-ssl-certificates-in-a-bundle
References:
https://github.com/request/request
https://github.com/twilio/twilio-node/blob/45858420688854494c2ed476a1997773c33a32a0/lib/Client.js
Ignore invalid self-signed ssl certificate in node.js with https.request?
It may be because of your internet connection.
After couple of minutes, if you have internet, try again and it should work.
Related
node: v10.19.0
request: v2.88.2
jsdom: v11.12.0
When I use my Nodejs app in my city home with optical fibre, everything is ok, but, when I use my Nodejs app at my summer house where I use mobile internet (T-mobile), I get this error (probably because of the different operator) when attempting to access some pages.
Error: write EPROTO 140216527574848:error:1414D172:SSL
routines:tls12_check_peer_sigalg:wrong signature
type:../ssl/t1_lib.c:1145:
Honestly, I have no idea what is going on. The only similar topic I have found is this:
cloud9 nodejs - Error: write EPROTO 140261073610560. and in localhost everything ok
var requestData = request(url, function(err, resp, HTMLdata) {
if (!err && resp.statusCode === 200) {
console.log('Request success \n');
}
});
I have a router from T-mobile (Huawei which does not have a bridge option).
So, if this is a port problem I can access the router, but, what should I change?
Description
Using node I make a typical API POST request for which I have a .catch block with response variable say err. On error, the response body is returned as such (as seen from the Hyperledger Composer REST app)
{
"error": {
"statusCode": 500,
"name": "Error",
"message": "error trying invoke chaincode. Error: chaincode error (status: 500, message: Error: Payment needs to be of positive value)",
"stack": "Error: error trying invoke chaincode. Error: chaincode error (status: 500, message: Error: Payment needs to be of positive value)\n at _initializeChannel.then.then.then.then.catch (/home/ubuntu/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/composer-connector-hlfv1/lib/hlfconnection.js:839:34)"
}
}
My Issue
I am simply trying to fetch the message property from the above response and send it to the UI. But weirdly err.message does not give me the value I see inside message but returns the entire response body(same with err.stack).
So basically -- err, err.message and err.stack returns the same output
How do I end up fetching only the value inside a property say message ?
PS:
err.statusCode does return the correct value ie. "500".
err.name returns "StatusCodeError"(not "Error" that I see in the response)
OK, so while not really a Hyperledger Composer question - you could try is it response.getBody() ? This is just an example, not a code snippet to use
var finalHost = "yoururl";
var r = new sn_ws.RESTMessageV2();
r.setHttpMethod("get");
r.setEndpoint(finalHost);
//r.setQueryParameter("locatenow", "true");
r.setBasicAuth(username,password);
var response = r.execute();
var responseBody = response.getBody();
// If response is in json format, directly you can send to client.
// If not then convert it.
return responseBody;
// On client side
var newoptions = JSON.parse(jsonstring);
// returned resp.
You might consider something like Restify for error handling on UI side ?
See README at bottom here https://github.com/restify/errors/blob/master/README.md ->
https://www.npmjs.com/package/restify-errors - see this S/O here
I'm using Firefox Nightly of 46.0a1 version (there is only 42v. for OS X, and Push API requires 43v).
And I'm getting this error:
DOMException [AbortError: "Error retrieving push subscription"
code: 20
nsresult: 0x80530014]
Here is snippet where this error in thrown:
navigator.serviceWorker.ready.then(function (serviceWorkerRegistration) {
serviceWorkerRegistration.pushManager.subscribe()
.then(function (subscription) {
endpoint = subscription.endpoint;
console.log('subscription endpoint: ', subscription.endpoint);
subscribeOnServer();
})
.catch(function (e) {
// here that error is raised
errorNotification.innerHTML = 'Unable to subscribe to push';
}
});
});
In Chrome this place doesn't throw anything and I get subscription with a properly endpoint.
I have recently found that this error may rise if your browser is behind a proxy which does not support web sockets (push service uses web sockets internally).
It doesn't throw for me.
There was a syntax error in your snippet, but I guess that wasn't the issue (otherwise it would have failed in Chrome as well).
Here's the snippet I've used:
navigator.serviceWorker.ready
.then(function(serviceWorkerRegistration) {
console.log('asd');
serviceWorkerRegistration.pushManager.subscribe()
.then(function(subscription) {
endpoint = subscription.endpoint;
console.log('subscription endpoint: ', subscription.endpoint);
})
.catch(function(e) {
console.log(e);
});
});
I got this error when my service-worker had errors(tried to access non existant store in indexedDb) and so even though it installed but push notifications were not getting subscribed with above error.
I have pasted a callback below that is in my waterline model
In order to give the client a pretty message I'm attempting to modify the status of the error object so that res.negotiate(err) will respond with badRequest. But my error.status = 400 seems to be ignored and when its passed to res.negotiate I still get 500 error returned (server error instead of bad request).
I'm working off of these docs
http://sailsjs.org/#/documentation/reference/res/res.negotiate.html
https://docs.nodejitsu.com/articles/errors/what-is-the-error-object
http://massalabs.com/dev/2013/10/17/handling-errors-in-nodejs.html
Thoughts, bug?
beforeDestroy: function(criteria, next){
var error = new Error('This shift has people scheduled and can not be deleted.');
error.type = 'user';
error.status = 400;
return next(error);
}
Also, even when I get a Server Error returned the message. In this case "This shift has people scheduled ..." can not be found on the error object that is returned? I'm using the unmodified response pages and I don't know why its being stripped out?
This is the error object being returned to the client.
error: "E_UNKNOWN"
raw: {}
status: 500
summary: "Encountered an unexpected error"
Looking at the source of the negotiate response, it appears that a 400 response should be returned:
'node_modules\sails\lib\hooks\responses\defaults\negotiate.js'
try {
statusCode = err.status || 500;
// Set the status
// (should be taken care of by res.* methods, but this sets a default just in case)
res.status(statusCode);
} catch (e) {}
// Respond using the appropriate custom response
if (statusCode === 403) return res.forbidden(body);
if (statusCode === 404) return res.notFound(body);
if (statusCode >= 400 && statusCode < 500) return res.badRequest(body);
I would suggest setting a break point within the negotiate response to verify it being called from the beforeDestroy model lifecycle callback.
I'm trying to get a webpage via node https.request(). Doing so results in an error getting logged by my code. Using the node request module has the same result:
problem with request: 140398870042432:error:140773F2:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert unexpected message:s23_clnt.c:658:
The following indicates the wrong SSL version is being used, but I cannot find a way to change the version: curl error: "sslv3 alert unexpected message". Using curl from my terminal returns a response as does hitting the URL in my browser (it is a login page). My code is below.
var request = require('request')
request.get("https://icmserver.wit.ie/balance", function(err, res, body) {
if (err) {
return console.log(err)
}
return body;
});
Does anyone have any idea what might be happening here?
Try to use options = { secureProtocol: 'SSLv3_method' } in the request you are making.
We hit the same problem. By default, request uses the https.globalAgent. So we added the code near the top of our script.
var https = require('https');
https.globalAgent.options.secureProtocol = 'SSLv3_method';
All of a sudden everything worked.
In case website uses ECDH curve, for me the issue resolved only by adding this option:
request({ url, agentOptions: {
ecdhCurve: 'P-521:P-384:P-256',
},(err,res,body) => {
JFYI, May be this will help someone.