{"action":"opened","issue":{"url":"https://api.github.com/repos/kriskowal/q/issues/669","labels_url":"https://api.github.com/repos/kriskowal/q/issues/669/labels{/name}","comments_url":"https://api.github.com/repos/kriskowal/q/issues/669/comments","events_url":"https://api.github.com/repos/kriskowal/q/issues/669/events","html_url":"https://github.com/kriskowal/q/issues/669","id":63969008,"number":669,"title":"Integrating JQuery with Q: promises stop working after some error","user":{"login":"slorber","id":749374,"avatar_url":"https://avatars.githubusercontent.com/u/749374?v=3","gravatar_id":"","url":"https://api.github.com/users/slorber","html_url":"https://github.com/slorber","followers_url":"https://api.github.com/users/slorber/followers","following_url":"https://api.github.com/users/slorber/following{/other_user}","gists_url":"https://api.github.com/users/slorber/gists{/gist_id}","starred_url":"https://api.github.com/users/slorber/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/slorber/subscriptions","organizations_url":"https://api.github.com/users/slorber/orgs","repos_url":"https://api.github.com/users/slorber/repos","events_url":"https://api.github.com/users/slorber/events{/privacy}","received_events_url":"https://api.github.com/users/slorber/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-03-24T11:03:14Z","updated_at":"2015-03-24T11:03:14Z","closed_at":null,"body":"Hi,\r\n\r\nI am using your JQuery integration code for more than 1 year without much troubles.\r\n\r\nIt worked fine for a while but I encountered a bug in my app due to a GET request with a too large payload. The reverse proxy respond 502, and subsequent calls of the browser for that request lead to a `ERR_CONNECTION_RESET`. This is somehow expected as my query string was too long and above the limits supported by Chrome.\r\n\r\nThe thing that seems very unexpected to me is that subsequent Ajax calls do not trigger Q's `then` methods, even if the requests are successful.\r\n\r\n\r\nI tried to hack around a little with the following code:\r\n\r\n\r\n```javascript\r\nexports.Qajax = function(ajaxOptions) {\r\n    var promise =  Q.promise(function (resolve,reject) {\r\n        console.error(\"REQ\",ajaxOptions);\r\n        try {\r\n            $.ajax(ajaxOptions)\r\n                .then(function (data, textStatus, jqXHR) {\r\n                    delete jqXHR.then; // treat xhr as a non-promise\r\n                    resolve(jqXHR);\r\n                    console.error(\"then success\",ajaxOptions,jqXHR);\r\n                }, function (jqXHR, textStatus, errorThrown) {\r\n                    delete jqXHR.then; // treat xhr as a non-promise\r\n                    resolve(jqXHR);\r\n                    console.error(\"then error\",ajaxOptions,jqXHR);\r\n                });\r\n        } catch (e) {\r\n            console.error(\"Could not issue ajax request\",e);\r\n            reject(e);\r\n        }\r\n    });\r\n    return promise.then(function(res) {\r\n        console.error(\"RES\",res);\r\n        return res;\r\n    });\r\n};\r\n```\r\n\r\nAfter the mentionned GET request error, the \"RES\" logger statement will never be fired again, while the \"then success\" and \"then error\" statements are still fired.\r\n\r\n\r\nNote that all my code that use the jquery promise integration above goes through this custom API client:\r\n\r\n```javascript\r\n// This permits to call the API:\r\n// - while automatically being authenticated\r\n// - being able to use relative API urls\r\n// - returning Q promises\r\nmodule.exports = function(ajaxOptions) {\r\n    prefixUrlWithBaseApiUrl(ajaxOptions);\r\n    configureForJsonCommunication(ajaxOptions);\r\n    var promise = QUtils.Qajax(ajaxOptions)\r\n        .then(function(response) {\r\n            return ApiResponseUtils.handleApiJsonResponse(response);\r\n        });\r\n    var isLocalhostRequest = isLocalhostUrl(ajaxOptions.url);\r\n    if ( isLocalhostRequest ) {\r\n        // For localhost requests we automatically delay the responses:\r\n        // permits to test the spinners  and concurrency issues (by using a random delay!)\r\n        var delayMillies = _.random(100,500);\r\n        return promise.delay(delayMillies);\r\n    } else {\r\n        return promise;\r\n    }\r\n\r\n};\r\n```\r\n\r\nNote that `ApiResponseUtils.handleApiJsonResponse(response);` may throw exceptions, and it does in case the response is unexpected (like 502, connection reset, unexpected response payload...). I don't think it's relevant mentionning that as for me the callbacks registered with `then` are not supposed to interfer with the resolution of the promise and the other `then` callbacks.\r\n\r\nI can reproduce this behavior on Chrome and Firefox\r\n\r\n\r\n"}}