{"action":"created","comment":{"url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/pulls/comments/46713106","id":46713106,"diff_hunk":"@@ -1,34 +1,83 @@\n-'use strict'; \r\n+'use strict';\r\n \r\n import SuperAgent from 'superagent';\r\n \r\n function RequestQueue( superAgent ) {\r\n-\t\r\n+\r\n \tlet Request = superAgent.Request;\r\n \tlet superAgentEnd = Request.prototype.end;\r\n-\r\n \tlet queue = [];\r\n \r\n-\t//Reset request to allow retry\r\n-\tfunction reset( obj, timeout ) {\r\n-\t\t\r\n-\t\tdelete obj.xhr;\r\n-\t\tdelete obj._timer;\r\n-\t\tdelete obj.aborted;\r\n-\t\tdelete obj.timedout;\r\n-\t\tdelete obj.timeout;\r\n+\tconst TIMEOUT_REGEX = /timeout of \\d+ms exceeded/;\r\n+\tconst CORS_REGEX = /Origin is not allowed by Access-Control-Allow-Origin/;\r\n+\r\n+\tlet RETRY_TIMEOUT;\r\n+\r\n+\t//HACK to Reset request to allow retry\r\n+\tfunction _resetRequest( request, timeout ) {\r\n+\r\n+\t\tlet headers = {};\r\n+\r\n+\t\tif ( request.req ) {\r\n+\t\t\theaders = request.req ? request.req._headers : {};\r\n+\t\t\trequest.req.abort();\r\n+\t\t}\r\n+\r\n+\t\trequest.called = false;\r\n+\t\trequest.timeout( timeout );\r\n+\r\n+\t\tdelete request._timer;\r\n+\t\tdelete request._aborted;\r\n+\t\tdelete request.timedout;\r\n+\t\tdelete request.req;\r\n+\t\tdelete request.xhr;\r\n+\r\n+\t\tlet headerKeys = Object.keys( headers );\r\n \r\n-\t\tobj.timeout( timeout );\r\n+\t\tfor( let i = 0; i < headerKeys.length; i++ ) {\r\n+\t\t\trequest.set( headerKeys[i], headers[headerKeys[i]] );\r\n+\t\t}\r\n \t}\r\n \r\n-\tfunction handleConnError( connErrorHandler, err ) {\r\n-\t\t\r\n-\t\tif( connErrorHandler ) {\r\n-\t\t\tconnErrorHandler( err );\r\n+\tfunction _returnResponse( fn, err, res ) {\r\n+\t\tif ( fn ) {\r\n+\t\t\tfn( err, res );\r\n \t\t}\r\n \t}\r\n \r\n-\tfunction pop() {\r\n+\tfunction _handleConnectionError( connectionErrorHandler, err ) {\r\n+\t\tif ( connectionErrorHandler ) {\r\n+\t\t\tconnectionErrorHandler( err );\r\n+\t\t}\r\n+\t}\r\n+\r\n+\tfunction _shouldAttempRetry( err, retryEnabled ) {\r\n+\r\n+\t\tif ( !retryEnabled || !err) {\r\n+\t\t\treturn false;\r\n+\t\t}\r\n+\r\n+\t\tlet gatewayOrServiceUnavailable =\r\n+\t\t\t\terr.status && ( err.status === 502 || err.status === 503 || err.status === 504 );\r\n+\r\n+\t\tlet requestTimedOut = TIMEOUT_REGEX.test( err ) || err.code ==='ECONNABORTED';\r\n+\r\n+\t\tif ( gatewayOrServiceUnavailable || requestTimedOut ) {\r\n+\t\t\tRETRY_TIMEOUT = 2000;\r\n+\t\t\treturn true;\r\n+\t\t}\r\n+\r\n+\t\tlet corsError = CORS_REGEX.test( err );\r\n+\r\n+\t\tif ( corsError ) {\r","path":"src/RequestQueue.js","position":89,"original_position":89,"commit_id":"e6391d0686ed08cbe9904577467caf2b7aab8d9e","original_commit_id":"e6391d0686ed08cbe9904577467caf2b7aab8d9e","user":{"login":"mdedys","id":3860427,"avatar_url":"https://avatars.githubusercontent.com/u/3860427?v=3","gravatar_id":"","url":"https://api.github.com/users/mdedys","html_url":"https://github.com/mdedys","followers_url":"https://api.github.com/users/mdedys/followers","following_url":"https://api.github.com/users/mdedys/following{/other_user}","gists_url":"https://api.github.com/users/mdedys/gists{/gist_id}","starred_url":"https://api.github.com/users/mdedys/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mdedys/subscriptions","organizations_url":"https://api.github.com/users/mdedys/orgs","repos_url":"https://api.github.com/users/mdedys/repos","events_url":"https://api.github.com/users/mdedys/events{/privacy}","received_events_url":"https://api.github.com/users/mdedys/received_events","type":"User","site_admin":false},"body":"This CORS check is required due to the fact that if you lose internet connection and try to contact LORES it will fail on the OPTIONS request and throw a generic CORS error. It is not possible( tried a bunch of different things) to decypher what the problem behind the CORS error was. Superagent just returns \"Origin is not allowed by Access-Control-Allow-Origin\".","created_at":"2015-12-04T18:18:36Z","updated_at":"2015-12-04T18:18:36Z","html_url":"https://github.com/Brightspace/superagent-d2l-queue/pull/4#discussion_r46713106","pull_request_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/pulls/4","_links":{"self":{"href":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/pulls/comments/46713106"},"html":{"href":"https://github.com/Brightspace/superagent-d2l-queue/pull/4#discussion_r46713106"},"pull_request":{"href":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/pulls/4"}}},"pull_request":{"url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/pulls/4","id":52702827,"html_url":"https://github.com/Brightspace/superagent-d2l-queue/pull/4","diff_url":"https://github.com/Brightspace/superagent-d2l-queue/pull/4.diff","patch_url":"https://github.com/Brightspace/superagent-d2l-queue/pull/4.patch","issue_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/issues/4","number":4,"state":"open","locked":false,"title":"U63683 - Refactoring and bug fixes","user":{"login":"mdedys","id":3860427,"avatar_url":"https://avatars.githubusercontent.com/u/3860427?v=3","gravatar_id":"","url":"https://api.github.com/users/mdedys","html_url":"https://github.com/mdedys","followers_url":"https://api.github.com/users/mdedys/followers","following_url":"https://api.github.com/users/mdedys/following{/other_user}","gists_url":"https://api.github.com/users/mdedys/gists{/gist_id}","starred_url":"https://api.github.com/users/mdedys/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mdedys/subscriptions","organizations_url":"https://api.github.com/users/mdedys/orgs","repos_url":"https://api.github.com/users/mdedys/repos","events_url":"https://api.github.com/users/mdedys/events{/privacy}","received_events_url":"https://api.github.com/users/mdedys/received_events","type":"User","site_admin":false},"body":"The majors changes were made to _shouldAttempRetry. I added some checks to determine if the request should be retried and not just rely on \"err\" being populated and \"res\" being undefined. Fixed a bug where it would not dequeue a request that had hard fail( 400 for example ). The rest of the changes to RequestQueue were refactoring.\r\n\r\nFor the tests I fixed the existing tests as there were some issues with nock and tests were passing when they shouldn't have. I also added tests for the queuing logic and retry logic","created_at":"2015-12-04T18:17:59Z","updated_at":"2015-12-04T18:18:36Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e7590eca1094932f2c17da9825084c10dcbd7fbb","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/pulls/4/commits","review_comments_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/pulls/4/comments","review_comment_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/issues/4/comments","statuses_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/statuses/e6391d0686ed08cbe9904577467caf2b7aab8d9e","head":{"label":"Brightspace:US63683","ref":"US63683","sha":"e6391d0686ed08cbe9904577467caf2b7aab8d9e","user":{"login":"Brightspace","id":5429170,"avatar_url":"https://avatars.githubusercontent.com/u/5429170?v=3","gravatar_id":"","url":"https://api.github.com/users/Brightspace","html_url":"https://github.com/Brightspace","followers_url":"https://api.github.com/users/Brightspace/followers","following_url":"https://api.github.com/users/Brightspace/following{/other_user}","gists_url":"https://api.github.com/users/Brightspace/gists{/gist_id}","starred_url":"https://api.github.com/users/Brightspace/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Brightspace/subscriptions","organizations_url":"https://api.github.com/users/Brightspace/orgs","repos_url":"https://api.github.com/users/Brightspace/repos","events_url":"https://api.github.com/users/Brightspace/events{/privacy}","received_events_url":"https://api.github.com/users/Brightspace/received_events","type":"Organization","site_admin":false},"repo":{"id":43303246,"name":"superagent-d2l-queue","full_name":"Brightspace/superagent-d2l-queue","owner":{"login":"Brightspace","id":5429170,"avatar_url":"https://avatars.githubusercontent.com/u/5429170?v=3","gravatar_id":"","url":"https://api.github.com/users/Brightspace","html_url":"https://github.com/Brightspace","followers_url":"https://api.github.com/users/Brightspace/followers","following_url":"https://api.github.com/users/Brightspace/following{/other_user}","gists_url":"https://api.github.com/users/Brightspace/gists{/gist_id}","starred_url":"https://api.github.com/users/Brightspace/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Brightspace/subscriptions","organizations_url":"https://api.github.com/users/Brightspace/orgs","repos_url":"https://api.github.com/users/Brightspace/repos","events_url":"https://api.github.com/users/Brightspace/events{/privacy}","received_events_url":"https://api.github.com/users/Brightspace/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Brightspace/superagent-d2l-queue","description":"Request queue using superagent and Q promise library","fork":false,"url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue","forks_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/forks","keys_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/teams","hooks_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/hooks","issue_events_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/issues/events{/number}","events_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/events","assignees_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/assignees{/user}","branches_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/branches{/branch}","tags_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/tags","blobs_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/git/refs{/sha}","trees_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/statuses/{sha}","languages_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/languages","stargazers_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/stargazers","contributors_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/contributors","subscribers_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/subscribers","subscription_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/subscription","commits_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/commits{/sha}","git_commits_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/git/commits{/sha}","comments_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/comments{/number}","issue_comment_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/issues/comments{/number}","contents_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/contents/{+path}","compare_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/merges","archive_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/downloads","issues_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/issues{/number}","pulls_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/pulls{/number}","milestones_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/milestones{/number}","notifications_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/labels{/name}","releases_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/releases{/id}","created_at":"2015-09-28T13:40:59Z","updated_at":"2015-10-07T20:10:31Z","pushed_at":"2015-12-04T18:17:59Z","git_url":"git://github.com/Brightspace/superagent-d2l-queue.git","ssh_url":"git@github.com:Brightspace/superagent-d2l-queue.git","clone_url":"https://github.com/Brightspace/superagent-d2l-queue.git","svn_url":"https://github.com/Brightspace/superagent-d2l-queue","homepage":null,"size":1364,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":2,"forks":0,"open_issues":2,"watchers":0,"default_branch":"master"}},"base":{"label":"Brightspace:master","ref":"master","sha":"32dcc9846314e942592cfbbfa279e5e7d90ea9a9","user":{"login":"Brightspace","id":5429170,"avatar_url":"https://avatars.githubusercontent.com/u/5429170?v=3","gravatar_id":"","url":"https://api.github.com/users/Brightspace","html_url":"https://github.com/Brightspace","followers_url":"https://api.github.com/users/Brightspace/followers","following_url":"https://api.github.com/users/Brightspace/following{/other_user}","gists_url":"https://api.github.com/users/Brightspace/gists{/gist_id}","starred_url":"https://api.github.com/users/Brightspace/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Brightspace/subscriptions","organizations_url":"https://api.github.com/users/Brightspace/orgs","repos_url":"https://api.github.com/users/Brightspace/repos","events_url":"https://api.github.com/users/Brightspace/events{/privacy}","received_events_url":"https://api.github.com/users/Brightspace/received_events","type":"Organization","site_admin":false},"repo":{"id":43303246,"name":"superagent-d2l-queue","full_name":"Brightspace/superagent-d2l-queue","owner":{"login":"Brightspace","id":5429170,"avatar_url":"https://avatars.githubusercontent.com/u/5429170?v=3","gravatar_id":"","url":"https://api.github.com/users/Brightspace","html_url":"https://github.com/Brightspace","followers_url":"https://api.github.com/users/Brightspace/followers","following_url":"https://api.github.com/users/Brightspace/following{/other_user}","gists_url":"https://api.github.com/users/Brightspace/gists{/gist_id}","starred_url":"https://api.github.com/users/Brightspace/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Brightspace/subscriptions","organizations_url":"https://api.github.com/users/Brightspace/orgs","repos_url":"https://api.github.com/users/Brightspace/repos","events_url":"https://api.github.com/users/Brightspace/events{/privacy}","received_events_url":"https://api.github.com/users/Brightspace/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Brightspace/superagent-d2l-queue","description":"Request queue using superagent and Q promise library","fork":false,"url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue","forks_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/forks","keys_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/teams","hooks_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/hooks","issue_events_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/issues/events{/number}","events_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/events","assignees_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/assignees{/user}","branches_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/branches{/branch}","tags_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/tags","blobs_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/git/refs{/sha}","trees_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/statuses/{sha}","languages_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/languages","stargazers_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/stargazers","contributors_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/contributors","subscribers_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/subscribers","subscription_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/subscription","commits_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/commits{/sha}","git_commits_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/git/commits{/sha}","comments_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/comments{/number}","issue_comment_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/issues/comments{/number}","contents_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/contents/{+path}","compare_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/merges","archive_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/downloads","issues_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/issues{/number}","pulls_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/pulls{/number}","milestones_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/milestones{/number}","notifications_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/labels{/name}","releases_url":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/releases{/id}","created_at":"2015-09-28T13:40:59Z","updated_at":"2015-10-07T20:10:31Z","pushed_at":"2015-12-04T18:17:59Z","git_url":"git://github.com/Brightspace/superagent-d2l-queue.git","ssh_url":"git@github.com:Brightspace/superagent-d2l-queue.git","clone_url":"https://github.com/Brightspace/superagent-d2l-queue.git","svn_url":"https://github.com/Brightspace/superagent-d2l-queue","homepage":null,"size":1364,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":2,"forks":0,"open_issues":2,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/pulls/4"},"html":{"href":"https://github.com/Brightspace/superagent-d2l-queue/pull/4"},"issue":{"href":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/issues/4"},"comments":{"href":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/issues/4/comments"},"review_comments":{"href":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/pulls/4/comments"},"review_comment":{"href":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/pulls/4/commits"},"statuses":{"href":"https://api.github.com/repos/Brightspace/superagent-d2l-queue/statuses/e6391d0686ed08cbe9904577467caf2b7aab8d9e"}}}}