{"action":"created","comment":{"url":"https://api.github.com/repos/cargomedia/CM/pulls/comments/31901031","id":31901031,"diff_hunk":"@@ -792,71 +807,52 @@ var CM_App = CM_Class_Abstract.extend({\n   /**\n    * @param {String} type\n    * @param {Object} data\n-   * @param {Object} [callbacks]\n-   * @return jqXHR\n+   * @return Promise\n    */\n-  ajax: function(type, data, callbacks) {\n-    callbacks = callbacks || {};\n+  ajax: function(type, data) {\n     var url = this.getUrlAjax(type);\n-    var errorHandler = function(msg, type, isPublic, callback) {\n-      if (!callback || callback(msg, type, isPublic) !== false) {\n-        cm.error.trigger(msg, type, isPublic);\n-      }\n-    };\n-    var jqXHR = $.ajax(url, {\n-      data: JSON.stringify(data),\n-      type: 'POST',\n-      dataType: 'json',\n-      contentType: 'application/json',\n-      cache: false\n-    });\n-    jqXHR.retry({times: 3, statusCodes: [405, 500, 503, 504]}).done(function(response) {\n-      if (response.error) {\n-        errorHandler(response.error.msg, response.error.type, response.error.isPublic, callbacks.error);\n-      } else if (response.success) {\n-        if (callbacks.success) {\n-          callbacks.success(response.success);\n-        }\n-      }\n-    }).fail(function(xhr, textStatus) {\n-      if (xhr.status === 0) {\n-        return; // Ignore interrupted ajax-request caused by leaving a page\n-      }\n \n-      var msg = cm.language.get('An unexpected connection problem occurred.');\n-      if (cm.options.debug) {\n-        msg = xhr.responseText || textStatus;\n-      }\n-      errorHandler(msg, null, false, callbacks.error);\n-    }).always(function() {\n-      if (callbacks.complete) {\n-        callbacks.complete();\n-      }\n-    });\n+    return new Promise(function(resolve, reject) {\n+      var jqXHR = $.ajax(url, {\n+        data: JSON.stringify(data),\n+        type: 'POST',\n+        dataType: 'json',\n+        contentType: 'application/json',\n+        cache: false\n+      });\n+      jqXHR.retry({times: 3, statusCodes: [405, 500, 503, 504]}).done(function(response) {\n+        if (response.error) {\n+          reject(cm.error.create(response.error));\n+        } else {\n+          resolve(response.success);\n+        }\n+      }).fail(function(xhr, textStatus) {\n+        if (xhr.status === 0) {\n+          return; // Ignore interrupted ajax-request caused by leaving a page\n+        }\n \n-    return jqXHR;\n+        var msg = cm.language.get('An unexpected connection problem occurred.');\n+        if (cm.options.debug) {\n+          msg = xhr.responseText || textStatus;\n+        }\n+        reject(cm.error.create({msg: msg, type: null, isPublic: false}));","path":"library/CM/App.js","position":100,"original_position":100,"commit_id":"b7503e709cdae5f50b7150d036df3a4fdc240132","original_commit_id":"b7503e709cdae5f50b7150d036df3a4fdc240132","user":{"login":"tomaszdurka","id":113303,"avatar_url":"https://avatars.githubusercontent.com/u/113303?v=3","gravatar_id":"","url":"https://api.github.com/users/tomaszdurka","html_url":"https://github.com/tomaszdurka","followers_url":"https://api.github.com/users/tomaszdurka/followers","following_url":"https://api.github.com/users/tomaszdurka/following{/other_user}","gists_url":"https://api.github.com/users/tomaszdurka/gists{/gist_id}","starred_url":"https://api.github.com/users/tomaszdurka/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tomaszdurka/subscriptions","organizations_url":"https://api.github.com/users/tomaszdurka/orgs","repos_url":"https://api.github.com/users/tomaszdurka/repos","events_url":"https://api.github.com/users/tomaszdurka/events{/privacy}","received_events_url":"https://api.github.com/users/tomaszdurka/received_events","type":"User","site_admin":false},"body":"I am not sure if I am so happy with this creation of errors.\r\nIs this in-between solution? I would prefer to keep errors simple with message only. Maybe we could replace type with additional error classes?\r\n","created_at":"2015-06-08T10:10:56Z","updated_at":"2015-06-08T10:10:56Z","html_url":"https://github.com/cargomedia/CM/pull/1754#discussion_r31901031","pull_request_url":"https://api.github.com/repos/cargomedia/CM/pulls/1754","_links":{"self":{"href":"https://api.github.com/repos/cargomedia/CM/pulls/comments/31901031"},"html":{"href":"https://github.com/cargomedia/CM/pull/1754#discussion_r31901031"},"pull_request":{"href":"https://api.github.com/repos/cargomedia/CM/pulls/1754"}}},"pull_request":{"url":"https://api.github.com/repos/cargomedia/CM/pulls/1754","id":34904093,"html_url":"https://github.com/cargomedia/CM/pull/1754","diff_url":"https://github.com/cargomedia/CM/pull/1754.diff","patch_url":"https://github.com/cargomedia/CM/pull/1754.patch","issue_url":"https://api.github.com/repos/cargomedia/CM/issues/1754","number":1754,"state":"open","locked":false,"title":"CM_App.ajax: Return usable Promise","user":{"login":"vogdb","id":372386,"avatar_url":"https://avatars.githubusercontent.com/u/372386?v=3","gravatar_id":"","url":"https://api.github.com/users/vogdb","html_url":"https://github.com/vogdb","followers_url":"https://api.github.com/users/vogdb/followers","following_url":"https://api.github.com/users/vogdb/following{/other_user}","gists_url":"https://api.github.com/users/vogdb/gists{/gist_id}","starred_url":"https://api.github.com/users/vogdb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vogdb/subscriptions","organizations_url":"https://api.github.com/users/vogdb/orgs","repos_url":"https://api.github.com/users/vogdb/repos","events_url":"https://api.github.com/users/vogdb/events{/privacy}","received_events_url":"https://api.github.com/users/vogdb/received_events","type":"User","site_admin":false},"body":"Currently `CM_App.ajax()` returns the original jqXHR \"Deferred\" object.\r\nIt only rejects if the ajax request fails (e.g. network problem or non-200 response). But if we experience an expected application error (e.g. \"auth required\") it will *resolve*.\r\n\r\nIt would be great if `ajax()` would return a usable \"Promise\", that:\r\n- Resolves when the request finished successfully (like `success` callback)\r\n- Rejects when the request fails (like `error` callback)\r\n\r\nWe should also consider using [ES6's Promise](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Promise) interface instead of jQuery's Promise: https://www.promisejs.org/#jquery\r\n\r\n@vogdb @tomaszdurka thoughts?","created_at":"2015-05-07T10:57:38Z","updated_at":"2015-06-08T10:10:56Z","closed_at":null,"merged_at":null,"merge_commit_sha":"32c21f5a3b462ad5f387560401e5b161eda6cb8a","assignee":{"login":"vogdb","id":372386,"avatar_url":"https://avatars.githubusercontent.com/u/372386?v=3","gravatar_id":"","url":"https://api.github.com/users/vogdb","html_url":"https://github.com/vogdb","followers_url":"https://api.github.com/users/vogdb/followers","following_url":"https://api.github.com/users/vogdb/following{/other_user}","gists_url":"https://api.github.com/users/vogdb/gists{/gist_id}","starred_url":"https://api.github.com/users/vogdb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vogdb/subscriptions","organizations_url":"https://api.github.com/users/vogdb/orgs","repos_url":"https://api.github.com/users/vogdb/repos","events_url":"https://api.github.com/users/vogdb/events{/privacy}","received_events_url":"https://api.github.com/users/vogdb/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/cargomedia/CM/pulls/1754/commits","review_comments_url":"https://api.github.com/repos/cargomedia/CM/pulls/1754/comments","review_comment_url":"https://api.github.com/repos/cargomedia/CM/pulls/comments{/number}","comments_url":"https://api.github.com/repos/cargomedia/CM/issues/1754/comments","statuses_url":"https://api.github.com/repos/cargomedia/CM/statuses/b7503e709cdae5f50b7150d036df3a4fdc240132","head":{"label":"vogdb:issue-1754","ref":"issue-1754","sha":"b7503e709cdae5f50b7150d036df3a4fdc240132","user":{"login":"vogdb","id":372386,"avatar_url":"https://avatars.githubusercontent.com/u/372386?v=3","gravatar_id":"","url":"https://api.github.com/users/vogdb","html_url":"https://github.com/vogdb","followers_url":"https://api.github.com/users/vogdb/followers","following_url":"https://api.github.com/users/vogdb/following{/other_user}","gists_url":"https://api.github.com/users/vogdb/gists{/gist_id}","starred_url":"https://api.github.com/users/vogdb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vogdb/subscriptions","organizations_url":"https://api.github.com/users/vogdb/orgs","repos_url":"https://api.github.com/users/vogdb/repos","events_url":"https://api.github.com/users/vogdb/events{/privacy}","received_events_url":"https://api.github.com/users/vogdb/received_events","type":"User","site_admin":false},"repo":{"id":23101151,"name":"CM","full_name":"vogdb/CM","owner":{"login":"vogdb","id":372386,"avatar_url":"https://avatars.githubusercontent.com/u/372386?v=3","gravatar_id":"","url":"https://api.github.com/users/vogdb","html_url":"https://github.com/vogdb","followers_url":"https://api.github.com/users/vogdb/followers","following_url":"https://api.github.com/users/vogdb/following{/other_user}","gists_url":"https://api.github.com/users/vogdb/gists{/gist_id}","starred_url":"https://api.github.com/users/vogdb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vogdb/subscriptions","organizations_url":"https://api.github.com/users/vogdb/orgs","repos_url":"https://api.github.com/users/vogdb/repos","events_url":"https://api.github.com/users/vogdb/events{/privacy}","received_events_url":"https://api.github.com/users/vogdb/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/vogdb/CM","description":"CM web application framework","fork":true,"url":"https://api.github.com/repos/vogdb/CM","forks_url":"https://api.github.com/repos/vogdb/CM/forks","keys_url":"https://api.github.com/repos/vogdb/CM/keys{/key_id}","collaborators_url":"https://api.github.com/repos/vogdb/CM/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/vogdb/CM/teams","hooks_url":"https://api.github.com/repos/vogdb/CM/hooks","issue_events_url":"https://api.github.com/repos/vogdb/CM/issues/events{/number}","events_url":"https://api.github.com/repos/vogdb/CM/events","assignees_url":"https://api.github.com/repos/vogdb/CM/assignees{/user}","branches_url":"https://api.github.com/repos/vogdb/CM/branches{/branch}","tags_url":"https://api.github.com/repos/vogdb/CM/tags","blobs_url":"https://api.github.com/repos/vogdb/CM/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/vogdb/CM/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/vogdb/CM/git/refs{/sha}","trees_url":"https://api.github.com/repos/vogdb/CM/git/trees{/sha}","statuses_url":"https://api.github.com/repos/vogdb/CM/statuses/{sha}","languages_url":"https://api.github.com/repos/vogdb/CM/languages","stargazers_url":"https://api.github.com/repos/vogdb/CM/stargazers","contributors_url":"https://api.github.com/repos/vogdb/CM/contributors","subscribers_url":"https://api.github.com/repos/vogdb/CM/subscribers","subscription_url":"https://api.github.com/repos/vogdb/CM/subscription","commits_url":"https://api.github.com/repos/vogdb/CM/commits{/sha}","git_commits_url":"https://api.github.com/repos/vogdb/CM/git/commits{/sha}","comments_url":"https://api.github.com/repos/vogdb/CM/comments{/number}","issue_comment_url":"https://api.github.com/repos/vogdb/CM/issues/comments{/number}","contents_url":"https://api.github.com/repos/vogdb/CM/contents/{+path}","compare_url":"https://api.github.com/repos/vogdb/CM/compare/{base}...{head}","merges_url":"https://api.github.com/repos/vogdb/CM/merges","archive_url":"https://api.github.com/repos/vogdb/CM/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/vogdb/CM/downloads","issues_url":"https://api.github.com/repos/vogdb/CM/issues{/number}","pulls_url":"https://api.github.com/repos/vogdb/CM/pulls{/number}","milestones_url":"https://api.github.com/repos/vogdb/CM/milestones{/number}","notifications_url":"https://api.github.com/repos/vogdb/CM/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/vogdb/CM/labels{/name}","releases_url":"https://api.github.com/repos/vogdb/CM/releases{/id}","created_at":"2014-08-19T07:34:20Z","updated_at":"2015-05-08T12:54:59Z","pushed_at":"2015-06-05T12:18:49Z","git_url":"git://github.com/vogdb/CM.git","ssh_url":"git@github.com:vogdb/CM.git","clone_url":"https://github.com/vogdb/CM.git","svn_url":"https://github.com/vogdb/CM","homepage":"","size":29303,"stargazers_count":0,"watchers_count":0,"language":"PHP","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"cargomedia:master","ref":"master","sha":"7a1ebb6febfdb9d4bb6529d0bc568d6e218355b2","user":{"login":"cargomedia","id":1699929,"avatar_url":"https://avatars.githubusercontent.com/u/1699929?v=3","gravatar_id":"","url":"https://api.github.com/users/cargomedia","html_url":"https://github.com/cargomedia","followers_url":"https://api.github.com/users/cargomedia/followers","following_url":"https://api.github.com/users/cargomedia/following{/other_user}","gists_url":"https://api.github.com/users/cargomedia/gists{/gist_id}","starred_url":"https://api.github.com/users/cargomedia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cargomedia/subscriptions","organizations_url":"https://api.github.com/users/cargomedia/orgs","repos_url":"https://api.github.com/users/cargomedia/repos","events_url":"https://api.github.com/users/cargomedia/events{/privacy}","received_events_url":"https://api.github.com/users/cargomedia/received_events","type":"Organization","site_admin":false},"repo":{"id":7134007,"name":"CM","full_name":"cargomedia/CM","owner":{"login":"cargomedia","id":1699929,"avatar_url":"https://avatars.githubusercontent.com/u/1699929?v=3","gravatar_id":"","url":"https://api.github.com/users/cargomedia","html_url":"https://github.com/cargomedia","followers_url":"https://api.github.com/users/cargomedia/followers","following_url":"https://api.github.com/users/cargomedia/following{/other_user}","gists_url":"https://api.github.com/users/cargomedia/gists{/gist_id}","starred_url":"https://api.github.com/users/cargomedia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cargomedia/subscriptions","organizations_url":"https://api.github.com/users/cargomedia/orgs","repos_url":"https://api.github.com/users/cargomedia/repos","events_url":"https://api.github.com/users/cargomedia/events{/privacy}","received_events_url":"https://api.github.com/users/cargomedia/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/cargomedia/CM","description":"CM web application framework","fork":false,"url":"https://api.github.com/repos/cargomedia/CM","forks_url":"https://api.github.com/repos/cargomedia/CM/forks","keys_url":"https://api.github.com/repos/cargomedia/CM/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cargomedia/CM/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cargomedia/CM/teams","hooks_url":"https://api.github.com/repos/cargomedia/CM/hooks","issue_events_url":"https://api.github.com/repos/cargomedia/CM/issues/events{/number}","events_url":"https://api.github.com/repos/cargomedia/CM/events","assignees_url":"https://api.github.com/repos/cargomedia/CM/assignees{/user}","branches_url":"https://api.github.com/repos/cargomedia/CM/branches{/branch}","tags_url":"https://api.github.com/repos/cargomedia/CM/tags","blobs_url":"https://api.github.com/repos/cargomedia/CM/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cargomedia/CM/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cargomedia/CM/git/refs{/sha}","trees_url":"https://api.github.com/repos/cargomedia/CM/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cargomedia/CM/statuses/{sha}","languages_url":"https://api.github.com/repos/cargomedia/CM/languages","stargazers_url":"https://api.github.com/repos/cargomedia/CM/stargazers","contributors_url":"https://api.github.com/repos/cargomedia/CM/contributors","subscribers_url":"https://api.github.com/repos/cargomedia/CM/subscribers","subscription_url":"https://api.github.com/repos/cargomedia/CM/subscription","commits_url":"https://api.github.com/repos/cargomedia/CM/commits{/sha}","git_commits_url":"https://api.github.com/repos/cargomedia/CM/git/commits{/sha}","comments_url":"https://api.github.com/repos/cargomedia/CM/comments{/number}","issue_comment_url":"https://api.github.com/repos/cargomedia/CM/issues/comments{/number}","contents_url":"https://api.github.com/repos/cargomedia/CM/contents/{+path}","compare_url":"https://api.github.com/repos/cargomedia/CM/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cargomedia/CM/merges","archive_url":"https://api.github.com/repos/cargomedia/CM/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cargomedia/CM/downloads","issues_url":"https://api.github.com/repos/cargomedia/CM/issues{/number}","pulls_url":"https://api.github.com/repos/cargomedia/CM/pulls{/number}","milestones_url":"https://api.github.com/repos/cargomedia/CM/milestones{/number}","notifications_url":"https://api.github.com/repos/cargomedia/CM/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cargomedia/CM/labels{/name}","releases_url":"https://api.github.com/repos/cargomedia/CM/releases{/id}","created_at":"2012-12-12T17:00:30Z","updated_at":"2015-05-07T11:04:07Z","pushed_at":"2015-06-05T14:36:00Z","git_url":"git://github.com/cargomedia/CM.git","ssh_url":"git@github.com:cargomedia/CM.git","clone_url":"https://github.com/cargomedia/CM.git","svn_url":"https://github.com/cargomedia/CM","homepage":"","size":39137,"stargazers_count":7,"watchers_count":7,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":15,"mirror_url":null,"open_issues_count":39,"forks":15,"open_issues":39,"watchers":7,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/cargomedia/CM/pulls/1754"},"html":{"href":"https://github.com/cargomedia/CM/pull/1754"},"issue":{"href":"https://api.github.com/repos/cargomedia/CM/issues/1754"},"comments":{"href":"https://api.github.com/repos/cargomedia/CM/issues/1754/comments"},"review_comments":{"href":"https://api.github.com/repos/cargomedia/CM/pulls/1754/comments"},"review_comment":{"href":"https://api.github.com/repos/cargomedia/CM/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/cargomedia/CM/pulls/1754/commits"},"statuses":{"href":"https://api.github.com/repos/cargomedia/CM/statuses/b7503e709cdae5f50b7150d036df3a4fdc240132"}}}}