This error happens when the date change in the date input happens very quickly. If I change the date every 2+ seconds, it works fine. But it gives the following error when the date input is changed very fast. In short, this error happens only when the next request is made right after the first one very quickly. I've spent hours and search a lot of similar issue with this error ERR_CONNECTION_REFUSED on SO and google, but no luck. Any ideas of what's causing this issue?
Also, when load the url (http://localhost:8000/svc/diary/2016-01-03) in browser, the data comes out fine, but if I reload (Ctrl + R) the url very fast, it goes to yahoo search with these terms:
http localhost 8000 svc diary 2016 01 03 diary
The Error Message from the console:
GET http://localhost:8000/svc/diary/2016-01-03 net::ERR_CONNECTION_REFUSED
send # jquery-2.2.0.js:9172
jQuery.extend.ajax # jquery-2.2.0.js:8653
(anonymous function) # idiary.js:18
jQuery.event.dispatch # jquery-2.2.0.js:4732
elemData.handle # jquery-2.2.0.js:4544
The Date form
<input class="form-control" id='ddate' type="date" name="bday">
The Ajax Call
$('#ddate').on('change', function() {
var ajaxParams = {
url: '/svc/diary/' + $(this).val(),
type: 'GET',
contentType: "application/json",
dataType:"json"
};
console.log(ajaxParams);
$.ajax(ajaxParams)
.done(function (data, textStatus, jqXHR) {
console.log("diary retrieved!")
console.log(data);
$("#diary").text(data.diary);
})
.fail(function (jqXHR, textStatus, errorThrown) {
$("#diary").text("");
console.log("failed to retrieve diary!");
console.log(errorThrown);
});
});
The backend node.js GET handler
function getDiary(req, res) {
var date = req.params.date;
util.log(mysql.format(searchQuery, [date]));
util.dbpool.query(searchQuery, [date], function (err, result) {
res.setHeader("Content-Type", "application/json");
if (err) {
console.log(err);
util.errLog(JSON.stringify(err));
res.status(500).json({message: 'summary, no results.'});
} else {
console.log(result);
result.length > 0 ? res.status(200).json(result[0]) : res.status(200).json({"ddate":date, "diary":""});
}
});
}
UPDATE: Just found out, this issue is gone when starting the node application server with
node server.js
This issue happens only when starting the node application server with pm2 or foerver
pm2 start --watch server.js
forever start --watch server.js
The issue is resolved. It was caused by using the watch flag in pm2 and forever. My app prints log statements, and the log folder is in the same level as the application folder, so whenever a log file is updated, pm2 is restarting my application server. That is why it works if I pin my application server every few seconds because the server restart only takes about a second. It gives connection refused error if I pin the server very fast, because the server is still restarting, that's why it's connection refused.
You are looking to make a cross domain request. By default server disallows this. You need to enable it on your server, and make a JSONP request. You can read about it here:
http://www.leggetter.co.uk/2010/03/12/making-cross-domain-javascript-requests-using-xmlhttprequest-or-xdomainrequest.html
What is JSONP all about?
Related
Developing a contact form using Nodejs/Express and create-react-app following this tutorial https://www.youtube.com/watch?v=o3eR0X91Ogs. The issue that I'm running into is that when I hit submit on the form the message succeeds, and I get it in my inbox. However, in the developer console, I am hit with the timeout error I set on the axios.post located in Contact.js, and in my terminal it logs message sent, console log located in index.js, immediately throwing the following error afterward:
HPM ERROR: Error: socket hang up
[1] at connResetException (internal/errors.js:612:14)
[1] at Socket.socketCloseListener (_http_client.js:443:25)
[1] at Socket.emit (events.js:326:22)
[1] at TCP.<anonymous> (net.js:673:12) {
[1] code: 'ECONNRESET'
[1] }
[1] [HPM] Error occurred while trying to proxy request /api/contact/ from localhost:3001 to http://localhost:3000/ (ECONNRESET) (https://nodejs.org/api/errors.html#errors_common_system_errors)
Does anyone know why this error is occurring, and how I can fix it? The message sends but hangs afterward which prevents the app state from resetting (resetForm). At the same time, the axios.post in Contact.js doesn't update the state of sent to true.
The Github repo for the project.
Edit: I've been stuck on this for a few days now. Looked at similar questions, attempted ALL the fixes I could find, and this error still persists.
This is a common misunderstanding about how ExpressJs responses work. If you don't send a response to the request, it'll be stuck forever. So all you have to do is to send a response! Also, the res variable was re-defined in the callback of sendMail function. Here is the fix:
app.post('/api/contact', (req, res) => {
// ...
smtpTransport.sendMail(mailOptions, (err, mailResponse) => {
if(err) {
console.log(err);
} else {
console.log('Message sent!');
}
smtpTransport.close();
return res.send(err ? err : 'Message sent!');
});
I am using Sails and Mysql to handle the database of my app. I recently clicked on a chrome autofill URL that took me to a 404'd page, since that url localhost:1337/companies was not active in this project.
Ever since I did that, my app returns
error: Sending 500 ("Server Error") response:
Error (E_UNKNOWN) :: Encountered an unexpected error
: ER_BAD_FIELD_ERROR: Unknown column 'NaN' in 'where clause'
and
Details: Error: ER_BAD_FIELD_ERROR: Unknown column 'NaN' in 'where clause'
any time I go to a url in my app. I tried cloning my app and relinking the database to no avail. I see this is a common issue people run into with sails, but none of the mentioned solutions were able to fix it for me.
Everything was working before I clicked that URL which makes me believe it may be a route issue, but the app still works, it will just fill up my terminal with the above errors.
Any help is greatly appreciated!
Edit: this is the custom API call I was working on in my controller.js when I started seeing the error:
winner: function (req, res) {
User.findOne({id: req.param('id')}).exec(function(err, user) {
if (err) {
return res.negotiate(err);
}
else {
var u = user;
u.totalwins++;
u.save();
sails.io.sockets.emit("chat", {verb:"score", data:{id: req.param('id'), name: user.name}});
}
});
}
Also receiving this error in my chrome-browser console:
:1337/user/quizzes Failed to load resource: the server responded with a status of 500 (Internal Server Error)
A node app is throwing this error when an HTTP POST request is made by our node express middleware using request library (error present only in a particular node app, no issues in others apps on the same machine using the middleware).
When external POST request is made (by middleware) to "http://outsite.com/requestData", POST doesn't work and error comes as "Error: connect ENOENT /requestData".
Code throwing error:
var requestLib = require('request');
var url = "http://httpbin.org/post";
var reqOptions = {
uri: url,
method: "POST",
headers: {
"Content-Type": "application/text"
},
timeout: 100000,
body: encodeURIComponent("Testing"),
forever: true, //keepalive
};
requestLib(reqOptions, function(error, response, body) {
if (error) {
console.log(error);
}
});
I experienced this issue on multiple machines. Running the identical code snippet you provided I found POSTs worked fine when using request#2.69.0 but consistently failed with Error: ENOENT for request#2.51.0 and various other minor versions < 2.69.
I suggest updating your package.json with the following to fix this issue:
"request": "~2.69.0".
Hope this helps - I was really scratching my head at inconsistent behavior across applications for a while.
For some reason this request GET never returns, but only in Node.js. I've tried in browser, curl, httparty, ruby's Net::Http, postman, clojure and they all work fine. Node.js will not.
This will return as you'd expect
echo "require('https').get('https://github.com/jakecraige.json', function(res) { console.log(res); });" | node
This never will return, it eventually throws an ECONNRESET
echo "require('https').get('https://gateway.rpx.realpage.com/rpxgateway/PricingAndAvailability.svc?wsdl', function(res) { console.log(res); });" | node
If anyone could provide some insight into this that would be extremely helpful.
Thanks!
Zyrri in IRC directed me to here which solved the problem.
SSL Error in nodejs
Looks like it wants SSLv3_method from node.js
$ curl 'https://gateway.rpx.realpage.com/rpxgateway/PricingAndAvailability.svc' -I
HTTP/1.1 400 Bad Request
Try providing an error handler and see what you get.
Your code hangs for me whichever URL I pick. I believe that's node trying to make sure we don't exit prematurely, running its event loop just in case. All other techniques you listed are synchronous, not event-driven. Also, res is probably not what you want to print, since it's the node's internal response object. Try this:
cat <<EOF | node
require("https").get("https://github.com/jakecraige.json",
function(res) {
var body = ''
res.
on('data', function(data) { body += data}).
on('end', function() { console.log(body); process.exit(0); });
}
);
EOF
Combining #Constarr links with this original post I have this constructed request getting a valid response.
var https = require('https');
https.globalAgent.options.secureProtocol = 'SSLv3_method';
https.get("https://gateway.rpx.realpage.com/rpxgateway/PricingAndAvailability.svc?wsdl", function(res) {
console.log("Got response: " + res.statusCode);
}).on('error', function(e) {
console.log("Got error: " + e.message);
});
Docs here
I am trying to setup SignalR at my ASP.NET MVC site and a Javascript client.
This is my client:
#section scripts{
<script src="~/Scripts/jquery.signalR-2.0.2.min.js"></script>
<script type="text/javascript">
$(function () {
var connection = $.connection('/MY_ENDPOINT');
connection.received(function (data) {
$('#chatArea').append('>>' + data + "\r\n");
});
connection.start().done(function () {
$("#send").click(function () {
connection.send($('#msg').val());
$("#msg").val("");
});
});
connection.error(function (e) {
console.log(e);
});
});
</script>
}
Of course, I have the corresponding HTML elements chatArea and msg. In server, here is what I did:
Installed SignalR (latest version currently, 2.0.2) through NuGet.
Added app.MapSignalR("MY_ENDPOINT", new Microsoft.AspNet.SignalR.HubConfiguration()); in startup configuration, made sure it is called before registering auth methods.
I've subclassed PersistentConnection and overridden OnConnected and OnReceived methods.
However, when I run my app and navigate to the page, I can see that my endpoint's negotiate and connect methods are called, they both return OK (HTTP 200). I try to send anything using the webpage by clicking the "send" button, and at the server side I'm getting this error:
A first chance exception of type 'Newtonsoft.Json.JsonReaderException'
occurred in Newtonsoft.Json.dll
Additional information: Unexpected character encountered while
parsing value: a. Path '', line 0, position 0.
What could be the cause of this error?
UPDATE: I also have an iOS app with the SignalR-ObjC framework, and I can connect. However, when I try to send any data over it, I'm getting:
2014-03-06 19:39:39.853 Tanisalim[54987:70b] Websocket error: Error Domain=AFNetworkingErrorDomain Code=-1011 "Request failed: internal server error (500)" UserInfo=0xade84e0 {NSErrorFailingURLKey=http://10.211.55.3/api/socket/send?transport=longPolling&connectionData=(null)&connectionToken=xybYQ8ItTN0IWUbyrosuHy%2F3jN0krIyHLO6b6Gq8VdC3orwRRGkVSIgtYkNQINVLhRMW77cX%2BU2LiHxoe0eDE3ZumT7JrObJcQ%2FXyHiP25%2BQy%2BZizHEHbsPyBBomERoI, NSLocalizedDescription=Request failed: internal server error (500), NSUnderlyingError=0xade1290 "Request failed: unacceptable content-type: text/html"
Still, no server-side breakpoints are hit.