Facing intermittent 404 issue when calling Rails API - ruby-on-rails

I have banged my head on this for 2 days now and i dint find any luck yet. Looking for help on this.
The issue:
Front End makes 10 similar XHR requests ( for different users ) to my Rails API and few of the requests randomly fails with 404 status code.
My Observations:
If i make the same request again, It passes.
I dont see any trace of 404 requests even hitting my server ( using logs ).
I do see different response headers for 200 and 404 ( mentioned below ) and i see cowboy ( https://github.com/heroku/cowboyku, https://github.com/heroku/vegur) server for 404 requests. I run my rails production with thin web server.
My theory is that, As few of my requests are not able to hit my thin server, they are getting 404. Now, the confusion is, Why is it hitting cowboy
200 Status Code
404 Status Code
[EDITS]
response payload for 404 errors is something like below.
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta charset="utf-8">
<title>No such app</title>
<style media="screen">
html,body,iframe {
margin: 0;
padding: 0;
}
html,body {
height: 100%;
overflow: hidden;
}
iframe {
width: 100%;
height: 100%;
border: 0;
}
</style>
</head>
<body>
<iframe src="//www.herokucdn.com/error-pages/no-such-app.html"></iframe>
</body>
</html>

Related

Rails HTTParty same 404 response in 2 different APIs

My Rails app just started to return 404 errors last Thursday on our Staging server, and I'm trying to figure out why. We hit 2 completely different APIs in our app, and they have been working for months. All of a sudden, we got 404 errors all morning, and without any changes, they work again.
We are using HTTParty to hit these external APIs. The response for both APIs are exactly the same, and it is a generic html template for 404 errors:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<title>404 - File or directory not found.</title>
<style type="text/css">
<!--
body{margin:0;font-size:.7em;font-family:Verdana, Arial, Helvetica, sans-serif;background:#EEEEEE;}
fieldset{padding:0 15px 10px 15px;}
h1{font-size:2.4em;margin:0;color:#FFF;}
h2{font-size:1.7em;margin:0;color:#CC0000;}
h3{font-size:1.2em;margin:10px 0 0 0;color:#000000;}
#header{width:96%;margin:0 0 0 0;padding:6px 2% 6px 2%;font-family:"trebuchet MS", Verdana, sans-serif;color:#FFF;
background-color:#555555;}
#content{margin:0 0 0 2%;position:relative;}
.content-container{background:#FFF;width:96%;margin-top:8px;padding:10px;position:relative;}
-->
</style>
</head>
<body>
<div id="header"><h1>Server Error</h1></div>
<div id="content">
<div class="content-container"><fieldset>
<h2>404 - File or directory not found.</h2>
<h3>The resource you are looking for might have been removed, had its name changed, or is temporarily unavailable.</h3>
</fieldset></div>
</div>
</body>
</html>
My initial guess is that we somehow hit the wrong endpoint for both, which is unlikely because we never changed anything and they have been working for months. But I tried to hit the wrong endpoint in one of the external API anyway, and this is the response I got:
<html>
<head><title>404 Not Found</title></head>
<body bgcolor=\"white\">
<center><h1>404 Not Found</h1></center>
<hr><center>nginx</center>
</body>
</html>
I noticed right away that these two 404 html templates are different, and at this point, I'm not sure what really happened. Since we got the same exact 404 response for both APIs, my hunch is that something is wrong on our side, not theirs, but I'm not 100% sure. I would really appreciate any help! Thanks!

How to make Bottle print error message in 500 response?

I'm trying to debug why Bottle can no longer find a template, but it doesn't tell me which template is actually missing:
File "/virtualenv/lib/python2.7/site-packages/bottle.py", line 3222, in __init__
raise TemplateError('Template %s not found.' % repr(name))
bottle.TemplateError
Neither the console nor the web page contain the formatted version of Template %s not found. anywhere.
I have enabled debugging (when debugging is disabled the stack trace does not show up on the web page).
The route handler is literally just #bottle.post('/request').
This is distinct from How to make Bottle print stacktrace when running through apache modwsgi?, since the answer there is to enable debugging.
Using the latest stable Bottle, 0.12.13.
This works for me - is your code substantially different? Hoping you'll spot a difference.
from bottle import Bottle, template
app = Bottle()
#app.route('/')
def home():
return template('foo') # template "foo" does not exist
app.run(host='127.0.0.1', port=8080) # Note: no debug required
Response:
% curl http://127.0.0.1:8080/
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html>
<head>
<title>Error: 500 Internal Server Error</title>
<style type="text/css">
html {background-color: #eee; font-family: sans;}
body {background-color: #fff; border: 1px solid #ddd;
padding: 15px; margin: 15px;}
pre {background-color: #eee; border: 1px solid #ddd; padding: 5px;}
</style>
</head>
<body>
<h1>Error: 500 Internal Server Error</h1>
<p>Sorry, the requested URL <tt>'http://127.0.0.1:8080/'</tt>
caused an error:</p>
<pre>Template 'foo' not found.</pre>
</body>
</html>
Note that the error message contains the missing template name:
Template 'foo' not found.

CodenameOne: Webview not scrollable in iOS version of app

I have a legacy cn1 app (using the old GUI builder) with a web browser component in the center of the Form (centered in a BorderLayout Container which is the main Form component). In the simulator as well as on an Android device the WebBrowser renders fine. In the iOS simulator the entire component shows up as a black rectangle, and on an iPhone (5s running iOS 9.1), the content of the WebBrowser is visible but doesn't scroll.
Is there some particular setting that needs to be changed for it be scrollable?
This is my code:
WebBrowser web = new WebBrowser() {
#Override
public void onLoad(String url) {
System.out.println("Article body webview loaded");
Component c = getInternal();
if (c instanceof BrowserComponent) {
BrowserComponent b = (BrowserComponent) c;
String text = ((String) m.currentArticleInfo.get("id"));
b.execute("loadArticle('" + text + "')");
}
}
};
((BrowserComponent) web.getInternal()).setNativeScrollingEnabled(true);
((BrowserComponent) web.getInternal()).setScrollVisible(false);
web.setScrollVisible(false);
web.setURL("jar:///article_body.html");
web.setScrollable(true);
web.getAllStyles().setPaddingTop(10);
form.addComponent(BorderLayout.CENTER, web);
I don't see any errors in the console. The web page code looks like this:
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="https://www.example.com/styles/style.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<style>
body::-webkit-scrollbar{
width: 0 !important;
}
#left_side_article #right #the_article #details_info{
font-size: 3.5mm !important;
}
div#the_article{
border: none !important;
}
div#the_article_header{
padding: 0 !important;
}
</style>
</head>
<body style="min-height: 100px">
<div id="left_side_article">
<div id="right">
<div id="the_article">
<div id="details_info" >
</div>
</div>
</div>
</div>
<script>
function loadArticle(content) {
console.log('in load article function, article id: ' + content);
var url = "https://www.example.com/api/article_body_ajax.php";
$.post(url,{"app_code": "myappcode", "id" : content},function(data,status,jqxhr){
$("#details_info").html(data);
$("#details_info img").each(function(){
$(this).attr("src", "https://www.example.com/" + $(this).attr("src"));
$(this).css("height", "auto");
});
});
};
</script>
</body>
</html>
Update
I tried debugging the WebView by downloading the app sources and using Safari to inspect the page. Safari recognized that there was a web page open in the app, and I was able to choose it from the Develop menu in Safari, but the inspect window was completely empty - no elements whatsoever.
I just committed a fix for the scrolling issue in iOS here. There was a bug that caused scrolling to be disabled if you call setNativeScrollingEnabled(true). This fix will be available in the next library update (next Friday). In the mean time, you can work around this by just not calling setNativeScrollingEnabled(true) - as the default is true anyways.
That might be related to changes we made to getComponentAt see if this is still happening after the update this weekend. We discussed some of the regressions related to this here: https://www.codenameone.com/blog/dont-touch-that-code.html

Google API malformed or illegal request

I issue the following request:
URI:
https://accounts.google.com/o/oauth2/token
HEADERS:
content-length 307
content-type application/x-www-form-urlencoded
BODY:
client_id=8633333333-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com&client_secret=dsfhosgoisdflkjsdfjlkssd&code=4%2skjsdhfsnfklfsjlkfsjlsfdcmMKts1jHnbrAAGls&grant_type=authorization_code&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive
The response I get is:
400 <!DOCTYPE html>
<html lang=en>
<meta charset=utf-8>
<meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width">
<title>Error 400 (Bad Request)!!1</title>
<style>
*{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}#media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}#logo{background:url(//www.google.com/images/branding/googlelogo/1x/googlelogo_color_150x54dp.png) no-repeat;margin-left:-5px}#media only screen and (min-resolution:192dpi){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat 0% 0%/100% 100%;-moz-border-image:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) 0}}#media only screen and (-webkit-min-device-pixel-ratio:2){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat;-webkit-background-size:100% 100%}}#logo{display:inline-block;height:54px;width:150px}
</style>
<a href=//www.google.com/><span id=logo aria-label=Google></span></a>
<p><b>400.</b> <ins>ThatΓÇÖs an error.</ins>
<p>Your client has issued a malformed or illegal request. <ins>ThatΓÇÖs all we know.</ins>
Please can anybody help me point to the mistake in the https request.
Thanks,
Milind
Thank you DalmTo. I tried that but that did not solve the problem. Then after carefully looking at each and every part of the request I saw that my socket library was sending the HTTP method as "GET" even though I was giving a body. Once I forced it to "POST" it worked!

JavaFX Webview letter-spacing Bug?

Currently I am using the JavaFx Webview to load a HTML page. But there is a problem when it loads the HTML page. It doesn't read the letter-spacing or -webkit-letter-spacing attribute in CSS. It's fine with the Chrome browser. How can I make it work in JavaFx?
<!doctype html>
<html>
<head>
<meta charset="utf-8"/>
<title>test</title>
<style>
.text {
letter-spacing: 20px;
}
</style>
</head>
<body>
<div class="text">
abcdefg
</div>
</body>
</html>
Looks like this property is not supported in JavaFX/JDK 7, but works for me in JavaFX/JDK 8. As far as I know, some of the WebViews rendering bugs fixed in JDK 8 won't be backported to JDK 7 and this one seems like being one of such bugs.

Resources