Ajax request to other websites don't work at heroku [closed] - ruby-on-rails

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
I have a Rails app which does an ajax request to the other web site when an user clicks on the button. On localhost it works just fine but at heroku it doesn't. It return "We're sorry, but something went wrong." (500) and here is the logs
Processing by HomeController#some_request as */*
2013-04-09T12:42:33.050720+00:00 app[web.1]: Parameters: {"q"=>"another_web_site.com"}
2013-04-09T12:42:33.048011+00:00 app[web.1]: Started POST "/ajax/some_request" for 180.183.158.162 at 2013-04-09 12:42:33 +0000
2013-04-09T12:42:29.793791+00:00 heroku[router]: at=info method=GET path=/assets/application.js host=my_host.org fwd="180.183.158.162" dyno=web.1 connect=1ms service=5ms status=304 bytes=0
2013-04-09T12:42:54.057280+00:00 app[web.1]:
2013-04-09T12:42:54.057280+00:00 app[web.1]: Errno::ETIMEDOUT (Connection timed out - connect(2)):
2013-04-09T12:42:54.057280+00:00 app[web.1]:
2013-04-09T12:42:54.057280+00:00 app[web.1]:
2013-04-09T12:42:54.057280+00:00 app[web.1]: lib/domain_info.rb:14:in `who_is'
2013-04-09T12:42:54.057280+00:00 app[web.1]: app/controllers/home_controller.rb:8:in `who_is'
2013-04-09T12:42:54.055802+00:00 app[web.1]: Completed 500 Internal Server Error in 21004ms
2013-04-09T12:42:54.059787+00:00 heroku[router]: at=info method=POST path=/ajax/some_request host=my_host.org fwd="180.183.158.162" dyno=web.1 connect=2ms service=21017ms status=500 bytes=643
Now it's timeout. Right yesterday it was https://devcenter.heroku.com/articles/error-codes#h18-request-interrupted where sock field was equal to client.
Why is that happening?

Whatever your app is doing in lib/domain_info.rb is timing out - are you sure that code works from locations other than your machine/localhost? What is that code doing? Sharing that would be helpful.

Related

Heroku[router] making GET request to "/assets/bundle.js.map"

Getting a weird error in my heroku logs:
heroku[router]: at=info method=GET path="/assets/bundle.js.map" host=syndicator1.herokuapp.com request_id=106a2ab1-c373-4e2c-817a-f740a2e0819b fwd="24.102.93.192" dyno=web.1 connect=1ms service=23ms status=404 bytes=1902 protocol=https
app[web.1]: Started GET "/assets/bundle.js.map"
ActionController::RoutingError (No route matches [GET] "/assets/bundle.js.map"):
I have no idea where this is coming from, I just know that my application isn't behaving the way it is in development. Any idea where to start fixing this?
EDIT:
The application works, mostly, in production. What doesn't work is the error-handling.
Here is what happens when I try to submit my form in development with invalid values:
Basically my Error-Box component gets triggered.
This is what happens when I do the same in production.
The Error-Box component does not get triggered. The 422 is correct, I want that but it should be triggering the error-box, instead I get the following in console:
Here is the code in the component that should trigger the error box,
handleSubmit(e) {
e.preventDefault();
const {addEvents,toggleModal,handleError} = this.props;
axios.post('/events', {
event: this.state
})
.then(function (response) {
const event = response.data.event;
toggleModal();
addEvents(event);
})
.catch(function (error) {
handleError(error.response.data);
});
}

iOS HTTPS request to Rails Heroku debugging 401 error

I am attempting to adapt this wenderlich tutorial to Swift 3 syntax to create an iOS frontned with rails backend hosted on Heroku.
Let me know if there is any other code that would be good to share, but it seems like an auth issue. Here's where the authorization header is set for the request:
let basicAuthString = "\(HTTPHelper.API_AUTH_NAME):\(HTTPHelper.API_AUTH_PASSWORD)"
let utf8str = basicAuthString.data(using: String.Encoding.utf8)
let base64EncodedString = utf8str?.base64EncodedString(options: Data.Base64EncodingOptions())
request.addValue("Basic \(base64EncodedString)", forHTTPHeaderField: "Authorization")
I am having trouble telling how to debug these requests to begin with. If I step through the code in the debugger, the request object seems pretty flat, and if I print the request I just see the URL.
The request to the heroku server (also built from that tutorial) returns a 401, and it doesn't seem to be entering any of the rails methods. It just returns a 401 unauthorized:
2017-03-24T20:13:47.022176+00:00 heroku[router]: at=info method=POST path="/api/signin" host=young-retreat-61850.herokuapp.com request_id=9d58e8f4-ee9f-4c73-babd-2a2ee5c82a4f fwd="73.83.200.10" dyno=web.1 connect=1ms service=13ms status=401 bytes=499 protocol=https
2017-03-24T20:13:47.014605+00:00 app[web.1]: Started POST "/api/signin" for 73.83.200.10 at 2017-03-24 20:13:47 +0000
2017-03-24T20:13:47.020239+00:00 app[web.1]: Processing by ApiController#signin as */*
2017-03-24T20:13:47.020279+00:00 app[web.1]: Parameters: {"email"=>"dsadsadsa", "password"=>"[FILTERED]", "api"=>{"email"=>"dsadsadsa", "password"=>"[FILTERED]"}}
2017-03-24T20:13:47.020671+00:00 app[web.1]: Filter chain halted as #<Proc:0x007f6ae4d6f140#/app/vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.5/lib/action_controller/metal/http_authentication.rb:71> rendered or redirected
2017-03-24T20:13:47.020791+00:00 app[web.1]: Completed 401 Unauthorized in 0ms (ActiveRecord: 0.0ms)
2017-03-24T20:13:47.142925+00:00 app[web.1]: Started POST "/api/signin" for 73.83.200.10 at 2017-03-24 20:13:47 +0000
2017-03-24T20:13:47.148098+00:00 app[web.1]: Processing by ApiController#signin as */*
2017-03-24T20:13:47.148134+00:00 app[web.1]: Parameters: {"email"=>"dsadsadsa", "password"=>"[FILTERED]", "api"=>{"email"=>"dsadsadsa", "password"=>"[FILTERED]"}}
2017-03-24T20:13:47.156450+00:00 app[web.1]: Filter chain halted as #<Proc:0x007f6ae4d6f140#/app/vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.5/lib/action_controller/metal/http_authentication.rb:71> rendered or redirected
2017-03-24T20:13:47.156647+00:00 app[web.1]: Completed 401 Unauthorized in 8ms (ActiveRecord: 0.0ms)
2017-03-24T20:13:47.157852+00:00 heroku[router]: at=info method=POST path="/api/signin" host=young-retreat-61850.herokuapp.com request_id=bc270aa1-aeed-40b8-b9a0-3c09a68dec8d fwd="73.83.200.10" dyno=web.1 connect=2ms service=24ms status=401 bytes=458 protocol=https
Should it seem strange that the nested "api" key has the same params? I am unclear on which direction to take for debugging these requests. I can't use a service like Charles because they are https right?
Feel like a fool...
the base64EncodedString was an optional.
fix:
request.addValue("Basic \(base64EncodedString!)", forHTTPHeaderField: "Authorization")
I was able to get more details about the request with this URLRequest method:
print("request header:\(request.allHTTPHeaderFields)")

"Poorly formatted HTTP response" in ruby on rails app in heroku

Our Production(SquareOff) and Staging(so-staging) App suddenly facing a terrible issue. The issue is when we send request to the app it failed to response. The response log is bellow:
2015-05-14T06:48:02.236633+00:00 heroku[router]: http_error="Invalid HTTP status line" at=error code=H17 desc="Poorly formatted HTTP response" method=POST path="/users/invitation" host=so-staging.herokuapp.com request_id=01f23953-580c-484a-9d6b-89ff19d70b2b fwd="203.202.242.130" dyno=web.1 connect=0ms service=1049ms status=503 bytes=755
However, sometimes it works perfectly. The response log is bellow for this scenario:
2015-05-14T06:43:10.129616+00:00 heroku[router]: at=info method=POST path="/users/invitation" host=so-staging.herokuapp.com request_id=cb961af7-c249-4705-8ed0-226fad76e6ab fwd="203.202.242.130" dyno=web.1 connect=1ms service=1362ms status=302 bytes=1317
Also i found this link that discuss about this issue. https://github.com/xyu/heroku-wp/issues/3 but the solution is really bad and don't acceptable.
I appreciate help regarding how to fix this issue.

Rails / Angular: Different returned JSON dev/production

I have a Rails backend, AngularJS frontend Single Page Application. It makes various ajax calls, which return JSON objects for the front end to use.
I'm using a postgres database for both development and production, served by heroku.
For a particular JSON call, I'm getting very different objects returned.
On development, it looks like this:
On production, it comes back looking like this:
What!? Is this minification at play?
Thanks greatly for any help.
Ok, here are the server requests
2014-12-05T12:37:14.608517+00:00 heroku[router]: at=info method=GET path="/api/itemprices/fromcleaner/80.json" host=www.60secondlaundry.com request_id=334d5cea-44bf-45d5-86a9-66e7fa8ea23e fwd="92.237.49.190" dyno=web.1 connect=1ms service=54ms status=304 bytes=467
2014-12-05T12:37:14.534106+00:00 heroku[router]: at=info method=GET path="/api/items.json" host=www.60secondlaundry.com request_id=4ba6050a-ea4e-4ba7-96a7-87cb111a811e fwd="92.237.49.190" dyno=web.1 connect=1ms service=18ms status=304 bytes=467
2014-12-05T12:37:14.570669+00:00 heroku[router]: at=info method=GET path="/api/cleaners/80.json" host=www.60secondlaundry.com request_id=b3016b72-3653-4a5e-9410-5bc2a797c300 fwd="92.237.49.190" dyno=web.1 connect=1ms service=13ms status=304 bytes=467
2014-12-05T12:37:14.772106+00:00 heroku[router]: at=info method=GET path="/api/reviews/fromcleaner/80.json" host=www.60secondlaundry.com request_id=25fe479e-cf86-4fd9-bc56-19536b9e83c2 fwd="92.237.49.190" dyno=web.1 connect=1ms service=212ms status=304 bytes=467
Here's the response
The response is essentially what you see in the screenshots above.
This is the line of code that prints out the two screenshots above:
Reviews.get(cleanerid).success(function(data, status, headers, config) {
console.log("getting reviews")
$scope.reviews = data.reviews
console.log(data.reviews)
});
Here's the "Reviews" factory object in the code above.
app.factory("Reviews", ['$http', function($http) {
var reviews = {};
reviews.get = function(id) {
return $http.get("/api/reviews/fromcleaner/" + id + ".json")
}
return reviews;
}]);

Heroku | how to read router logs

So my typical router log on the Cedar platform looks might look like
2012-03-22T18:26:34+00:00 heroku[router]: GET [my_url] dyno=web.9 queue=0 wait=0ms service=228ms status=302 bytes=212
2012-03-22T18:26:36+00:00 heroku[router]: GET [my_url] dyno=web.7 queue=0 wait=0ms service=23ms status=200 bytes=360
2012-03-22T18:26:45+00:00 heroku[router]: GET [my_url] dyno=web.30 queue=0 wait=0ms service=348ms status=201 bytes=1
I want to confirm my understanding of the terms queue, wait and service
My initial thoughts where that:
queue: The name of the queue if using background_job or resque
wait: how long is the request waiting in the router (Request Queueing in New Relic)
service: how long it actually takes your application to handle the request (not including queing time)
But my wait in my logs is always 0ms. Even if I have significant backlog.
Are my definitions wrong?
Queue: The number of requests waiting to be processed by a dyno.
Wait: The length of time this request sat in the queue before being processed.
Service: The processing time of the request.
Your total response time will be wait + service.

Resources