{"action":"created","issue":{"url":"https://api.github.com/repos/learningequality/ka-lite/issues/4203","labels_url":"https://api.github.com/repos/learningequality/ka-lite/issues/4203/labels{/name}","comments_url":"https://api.github.com/repos/learningequality/ka-lite/issues/4203/comments","events_url":"https://api.github.com/repos/learningequality/ka-lite/issues/4203/events","html_url":"https://github.com/learningequality/ka-lite/issues/4203","id":99077632,"number":4203,"title":"api.js -- handleFailedAPI callback problematic","user":{"login":"MCGallaspy","id":8888020,"avatar_url":"https://avatars.githubusercontent.com/u/8888020?v=3","gravatar_id":"","url":"https://api.github.com/users/MCGallaspy","html_url":"https://github.com/MCGallaspy","followers_url":"https://api.github.com/users/MCGallaspy/followers","following_url":"https://api.github.com/users/MCGallaspy/following{/other_user}","gists_url":"https://api.github.com/users/MCGallaspy/gists{/gist_id}","starred_url":"https://api.github.com/users/MCGallaspy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MCGallaspy/subscriptions","organizations_url":"https://api.github.com/users/MCGallaspy/orgs","repos_url":"https://api.github.com/users/MCGallaspy/repos","events_url":"https://api.github.com/users/MCGallaspy/events{/privacy}","received_events_url":"https://api.github.com/users/MCGallaspy/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/learningequality/ka-lite/labels/bug","name":"bug","color":"e11d21"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/learningequality/ka-lite/milestones/48","html_url":"https://github.com/learningequality/ka-lite/milestones/0.15.0","labels_url":"https://api.github.com/repos/learningequality/ka-lite/milestones/48/labels","id":1028214,"number":48,"title":"0.15.0","description":"","creator":{"login":"aronasorman","id":191955,"avatar_url":"https://avatars.githubusercontent.com/u/191955?v=3","gravatar_id":"","url":"https://api.github.com/users/aronasorman","html_url":"https://github.com/aronasorman","followers_url":"https://api.github.com/users/aronasorman/followers","following_url":"https://api.github.com/users/aronasorman/following{/other_user}","gists_url":"https://api.github.com/users/aronasorman/gists{/gist_id}","starred_url":"https://api.github.com/users/aronasorman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aronasorman/subscriptions","organizations_url":"https://api.github.com/users/aronasorman/orgs","repos_url":"https://api.github.com/users/aronasorman/repos","events_url":"https://api.github.com/users/aronasorman/events{/privacy}","received_events_url":"https://api.github.com/users/aronasorman/received_events","type":"User","site_admin":false},"open_issues":145,"closed_issues":20,"state":"open","created_at":"2015-03-18T22:06:13Z","updated_at":"2015-08-04T22:48:58Z","due_on":"2015-09-30T07:00:00Z","closed_at":null},"comments":2,"created_at":"2015-08-04T22:48:58Z","updated_at":"2015-08-04T22:57:47Z","closed_at":null,"body":"It's possible for the error callback of a jqxhr object to be called even is the response's status is 200 -- in particular if there's a parse error.\r\n\r\nThat makes this snippet from `api.js` problematic, if the response content type is HTML (when it expects JSON):\r\n```js\r\nvar error_msg = sprintf(\"%s<br/>%s<br/>%s\", resp.status, resp.responseText, resp);\r\nmessages = {error: sprintf(gettext(\"Unexpected error; contact the FLE with the following information: %(error_msg)s\"), {error_msg: error_msg})};\r\n```\r\n\r\nAll the HTML will be printed out in the error bubble, which we've seen in several different issues now. It's possible to reproduce this using Backbone.Models by setting the url attribute to an endpoint which serves HTML, but the fastest way to see what's happening is to try this in the console on the learn page:\r\n```js\r\n$.ajax({ url: \"#\", dataType: \"json\" }).done( function() { console.log(\"success\"); }).fail( function() { console.log(\"failure\"); });\r\n```\r\n\r\nNote the problem is the `dataType` header is being set to `json` when `html` is returned. Changing `dataType` to `html` will call the success callback.\r\n\r\nThere's a couple of ways to handle this:\r\n1) In our views, reject requests with the wrong dataType header.\r\n2) In `api.js`, handle `parseerror` separately from other error types.\r\n\r\nThe first one is more explicit but will probably require more work -- it's also possible that some existing features rely on this weird behavior. For the second one will be pretty quick to implement, but seems to address the symptom rather than the cause. By which I mean there's the possibility that we will handle some future, unrelated parseerror incorrectly.\r\n\r\n@rtibbles @aronasorman @jamalex thoughts on this?"},"comment":{"url":"https://api.github.com/repos/learningequality/ka-lite/issues/comments/127788673","html_url":"https://github.com/learningequality/ka-lite/issues/4203#issuecomment-127788673","issue_url":"https://api.github.com/repos/learningequality/ka-lite/issues/4203","id":127788673,"user":{"login":"MCGallaspy","id":8888020,"avatar_url":"https://avatars.githubusercontent.com/u/8888020?v=3","gravatar_id":"","url":"https://api.github.com/users/MCGallaspy","html_url":"https://github.com/MCGallaspy","followers_url":"https://api.github.com/users/MCGallaspy/followers","following_url":"https://api.github.com/users/MCGallaspy/following{/other_user}","gists_url":"https://api.github.com/users/MCGallaspy/gists{/gist_id}","starred_url":"https://api.github.com/users/MCGallaspy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MCGallaspy/subscriptions","organizations_url":"https://api.github.com/users/MCGallaspy/orgs","repos_url":"https://api.github.com/users/MCGallaspy/repos","events_url":"https://api.github.com/users/MCGallaspy/events{/privacy}","received_events_url":"https://api.github.com/users/MCGallaspy/received_events","type":"User","site_admin":false},"created_at":"2015-08-04T22:57:47Z","updated_at":"2015-08-04T22:57:47Z","body":"It wouldn't. But as I've noted, several bugs we've seen now had been making an ajax request to endpoints which returned html."}}