{"action":"created","comment":{"url":"https://api.github.com/repos/docker/docker/pulls/comments/39512675","id":39512675,"diff_hunk":"@@ -187,28 +188,71 @@ func httpError(w http.ResponseWriter, err error) {\n \t\tlogrus.WithFields(logrus.Fields{\"error\": err, \"writer\": w}).Error(\"unexpected HTTP error handling\")\n \t\treturn\n \t}\n+\n \tstatusCode := http.StatusInternalServerError\n-\t// FIXME: this is brittle and should not be necessary.\n-\t// If we need to differentiate between different possible error types, we should\n-\t// create appropriate error types with clearly defined meaning.\n-\terrStr := strings.ToLower(err.Error())\n-\tfor keyword, status := range map[string]int{\n-\t\t\"not found\":             http.StatusNotFound,\n-\t\t\"no such\":               http.StatusNotFound,\n-\t\t\"bad parameter\":         http.StatusBadRequest,\n-\t\t\"conflict\":              http.StatusConflict,\n-\t\t\"impossible\":            http.StatusNotAcceptable,\n-\t\t\"wrong login/password\":  http.StatusUnauthorized,\n-\t\t\"hasn't been activated\": http.StatusForbidden,\n-\t} {\n-\t\tif strings.Contains(errStr, keyword) {\n-\t\t\tstatusCode = status\n-\t\t\tbreak\n+\terrMsg := err.Error()\n+\n+\t// Based on the type of error we get we need to process things\n+\t// slightly differently to extract the error message.\n+\t// In the 'errcode.*' cases there are two different type of\n+\t// error that could be returned. errocode.ErrorCode is the base\n+\t// type of error object - it is just an 'int' that can then be\n+\t// used as the look-up key to find the message. errorcode.Error\n+\t// extends errorcode.Error by adding error-instance specific\n+\t// data, like 'details' or variable strings to be inserted into\n+\t// the message.\n+\t//\n+\t// Ideally, we should just be able to call err.Error() for all\n+\t// cases but the errcode package doesn't support that yet.\n+\t//\n+\t// Additionally, in both errcode cases, there might be an http\n+\t// status code associated with it, and if so use it.\n+\tswitch err.(type) {\n+\tcase errcode.ErrorCode:\n+\t\tdaError, _ := err.(errcode.ErrorCode)","path":"api/server/server.go","position":49,"original_position":49,"commit_id":"628b9a41b09fde3ce1493f7d4f1495b9afaa506c","original_commit_id":"628b9a41b09fde3ce1493f7d4f1495b9afaa506c","user":{"login":"thaJeztah","id":1804568,"avatar_url":"https://avatars.githubusercontent.com/u/1804568?v=3","gravatar_id":"","url":"https://api.github.com/users/thaJeztah","html_url":"https://github.com/thaJeztah","followers_url":"https://api.github.com/users/thaJeztah/followers","following_url":"https://api.github.com/users/thaJeztah/following{/other_user}","gists_url":"https://api.github.com/users/thaJeztah/gists{/gist_id}","starred_url":"https://api.github.com/users/thaJeztah/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thaJeztah/subscriptions","organizations_url":"https://api.github.com/users/thaJeztah/orgs","repos_url":"https://api.github.com/users/thaJeztah/repos","events_url":"https://api.github.com/users/thaJeztah/events{/privacy}","received_events_url":"https://api.github.com/users/thaJeztah/received_events","type":"User","site_admin":false},"body":"`thaError`? :wink:","created_at":"2015-09-15T14:00:10Z","updated_at":"2015-09-15T14:00:10Z","html_url":"https://github.com/docker/docker/pull/15069#discussion_r39512675","pull_request_url":"https://api.github.com/repos/docker/docker/pulls/15069","_links":{"self":{"href":"https://api.github.com/repos/docker/docker/pulls/comments/39512675"},"html":{"href":"https://github.com/docker/docker/pull/15069#discussion_r39512675"},"pull_request":{"href":"https://api.github.com/repos/docker/docker/pulls/15069"}}},"pull_request":{"url":"https://api.github.com/repos/docker/docker/pulls/15069","id":40972514,"html_url":"https://github.com/docker/docker/pull/15069","diff_url":"https://github.com/docker/docker/pull/15069.diff","patch_url":"https://github.com/docker/docker/pull/15069.patch","issue_url":"https://api.github.com/repos/docker/docker/issues/15069","number":15069,"state":"closed","locked":false,"title":"Use the new error package","user":{"login":"duglin","id":1944671,"avatar_url":"https://avatars.githubusercontent.com/u/1944671?v=3","gravatar_id":"","url":"https://api.github.com/users/duglin","html_url":"https://github.com/duglin","followers_url":"https://api.github.com/users/duglin/followers","following_url":"https://api.github.com/users/duglin/following{/other_user}","gists_url":"https://api.github.com/users/duglin/gists{/gist_id}","starred_url":"https://api.github.com/users/duglin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/duglin/subscriptions","organizations_url":"https://api.github.com/users/duglin/orgs","repos_url":"https://api.github.com/users/duglin/repos","events_url":"https://api.github.com/users/duglin/events{/privacy}","received_events_url":"https://api.github.com/users/duglin/received_events","type":"User","site_admin":false},"body":"This is the first step in converting out static strings into well-defined\r\nerror types.  This shows just a few examples of it to get a feel for how things\r\nwill look. Once we agree on the basic outline we can then work on converting\r\nthe rest of the code over.\r\n\r\nping @crosbymichael @stevvooe \r\n\r\nSigned-off-by: Doug Davis <dug@us.ibm.com>","created_at":"2015-07-28T03:35:30Z","updated_at":"2015-09-15T14:00:11Z","closed_at":"2015-09-15T13:28:53Z","merged_at":"2015-09-15T13:28:53Z","merge_commit_sha":"2ca208a1712389525e8e9ff7cd9ced94fd6fb3ae","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/docker/docker/pulls/15069/commits","review_comments_url":"https://api.github.com/repos/docker/docker/pulls/15069/comments","review_comment_url":"https://api.github.com/repos/docker/docker/pulls/comments{/number}","comments_url":"https://api.github.com/repos/docker/docker/issues/15069/comments","statuses_url":"https://api.github.com/repos/docker/docker/statuses/628b9a41b09fde3ce1493f7d4f1495b9afaa506c","head":{"label":"duglin:UseErrorPackage","ref":"UseErrorPackage","sha":"628b9a41b09fde3ce1493f7d4f1495b9afaa506c","user":{"login":"duglin","id":1944671,"avatar_url":"https://avatars.githubusercontent.com/u/1944671?v=3","gravatar_id":"","url":"https://api.github.com/users/duglin","html_url":"https://github.com/duglin","followers_url":"https://api.github.com/users/duglin/followers","following_url":"https://api.github.com/users/duglin/following{/other_user}","gists_url":"https://api.github.com/users/duglin/gists{/gist_id}","starred_url":"https://api.github.com/users/duglin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/duglin/subscriptions","organizations_url":"https://api.github.com/users/duglin/orgs","repos_url":"https://api.github.com/users/duglin/repos","events_url":"https://api.github.com/users/duglin/events{/privacy}","received_events_url":"https://api.github.com/users/duglin/received_events","type":"User","site_admin":false},"repo":{"id":22769065,"name":"docker","full_name":"duglin/docker","owner":{"login":"duglin","id":1944671,"avatar_url":"https://avatars.githubusercontent.com/u/1944671?v=3","gravatar_id":"","url":"https://api.github.com/users/duglin","html_url":"https://github.com/duglin","followers_url":"https://api.github.com/users/duglin/followers","following_url":"https://api.github.com/users/duglin/following{/other_user}","gists_url":"https://api.github.com/users/duglin/gists{/gist_id}","starred_url":"https://api.github.com/users/duglin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/duglin/subscriptions","organizations_url":"https://api.github.com/users/duglin/orgs","repos_url":"https://api.github.com/users/duglin/repos","events_url":"https://api.github.com/users/duglin/events{/privacy}","received_events_url":"https://api.github.com/users/duglin/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/duglin/docker","description":"Docker - the open-source application container engine","fork":true,"url":"https://api.github.com/repos/duglin/docker","forks_url":"https://api.github.com/repos/duglin/docker/forks","keys_url":"https://api.github.com/repos/duglin/docker/keys{/key_id}","collaborators_url":"https://api.github.com/repos/duglin/docker/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/duglin/docker/teams","hooks_url":"https://api.github.com/repos/duglin/docker/hooks","issue_events_url":"https://api.github.com/repos/duglin/docker/issues/events{/number}","events_url":"https://api.github.com/repos/duglin/docker/events","assignees_url":"https://api.github.com/repos/duglin/docker/assignees{/user}","branches_url":"https://api.github.com/repos/duglin/docker/branches{/branch}","tags_url":"https://api.github.com/repos/duglin/docker/tags","blobs_url":"https://api.github.com/repos/duglin/docker/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/duglin/docker/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/duglin/docker/git/refs{/sha}","trees_url":"https://api.github.com/repos/duglin/docker/git/trees{/sha}","statuses_url":"https://api.github.com/repos/duglin/docker/statuses/{sha}","languages_url":"https://api.github.com/repos/duglin/docker/languages","stargazers_url":"https://api.github.com/repos/duglin/docker/stargazers","contributors_url":"https://api.github.com/repos/duglin/docker/contributors","subscribers_url":"https://api.github.com/repos/duglin/docker/subscribers","subscription_url":"https://api.github.com/repos/duglin/docker/subscription","commits_url":"https://api.github.com/repos/duglin/docker/commits{/sha}","git_commits_url":"https://api.github.com/repos/duglin/docker/git/commits{/sha}","comments_url":"https://api.github.com/repos/duglin/docker/comments{/number}","issue_comment_url":"https://api.github.com/repos/duglin/docker/issues/comments{/number}","contents_url":"https://api.github.com/repos/duglin/docker/contents/{+path}","compare_url":"https://api.github.com/repos/duglin/docker/compare/{base}...{head}","merges_url":"https://api.github.com/repos/duglin/docker/merges","archive_url":"https://api.github.com/repos/duglin/docker/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/duglin/docker/downloads","issues_url":"https://api.github.com/repos/duglin/docker/issues{/number}","pulls_url":"https://api.github.com/repos/duglin/docker/pulls{/number}","milestones_url":"https://api.github.com/repos/duglin/docker/milestones{/number}","notifications_url":"https://api.github.com/repos/duglin/docker/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/duglin/docker/labels{/name}","releases_url":"https://api.github.com/repos/duglin/docker/releases{/id}","created_at":"2014-08-08T19:24:58Z","updated_at":"2015-05-21T21:18:31Z","pushed_at":"2015-09-15T13:35:13Z","git_url":"git://github.com/duglin/docker.git","ssh_url":"git@github.com:duglin/docker.git","clone_url":"https://github.com/duglin/docker.git","svn_url":"https://github.com/duglin/docker","homepage":"http://www.docker.com","size":69755,"stargazers_count":3,"watchers_count":3,"language":"Go","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":3,"default_branch":"master"}},"base":{"label":"docker:master","ref":"master","sha":"084f8060e28842fa6d23aa8b83ea357a2650cc41","user":{"login":"docker","id":5429470,"avatar_url":"https://avatars.githubusercontent.com/u/5429470?v=3","gravatar_id":"","url":"https://api.github.com/users/docker","html_url":"https://github.com/docker","followers_url":"https://api.github.com/users/docker/followers","following_url":"https://api.github.com/users/docker/following{/other_user}","gists_url":"https://api.github.com/users/docker/gists{/gist_id}","starred_url":"https://api.github.com/users/docker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/docker/subscriptions","organizations_url":"https://api.github.com/users/docker/orgs","repos_url":"https://api.github.com/users/docker/repos","events_url":"https://api.github.com/users/docker/events{/privacy}","received_events_url":"https://api.github.com/users/docker/received_events","type":"Organization","site_admin":false},"repo":{"id":7691631,"name":"docker","full_name":"docker/docker","owner":{"login":"docker","id":5429470,"avatar_url":"https://avatars.githubusercontent.com/u/5429470?v=3","gravatar_id":"","url":"https://api.github.com/users/docker","html_url":"https://github.com/docker","followers_url":"https://api.github.com/users/docker/followers","following_url":"https://api.github.com/users/docker/following{/other_user}","gists_url":"https://api.github.com/users/docker/gists{/gist_id}","starred_url":"https://api.github.com/users/docker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/docker/subscriptions","organizations_url":"https://api.github.com/users/docker/orgs","repos_url":"https://api.github.com/users/docker/repos","events_url":"https://api.github.com/users/docker/events{/privacy}","received_events_url":"https://api.github.com/users/docker/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/docker/docker","description":"Docker - the open-source application container engine","fork":false,"url":"https://api.github.com/repos/docker/docker","forks_url":"https://api.github.com/repos/docker/docker/forks","keys_url":"https://api.github.com/repos/docker/docker/keys{/key_id}","collaborators_url":"https://api.github.com/repos/docker/docker/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/docker/docker/teams","hooks_url":"https://api.github.com/repos/docker/docker/hooks","issue_events_url":"https://api.github.com/repos/docker/docker/issues/events{/number}","events_url":"https://api.github.com/repos/docker/docker/events","assignees_url":"https://api.github.com/repos/docker/docker/assignees{/user}","branches_url":"https://api.github.com/repos/docker/docker/branches{/branch}","tags_url":"https://api.github.com/repos/docker/docker/tags","blobs_url":"https://api.github.com/repos/docker/docker/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/docker/docker/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/docker/docker/git/refs{/sha}","trees_url":"https://api.github.com/repos/docker/docker/git/trees{/sha}","statuses_url":"https://api.github.com/repos/docker/docker/statuses/{sha}","languages_url":"https://api.github.com/repos/docker/docker/languages","stargazers_url":"https://api.github.com/repos/docker/docker/stargazers","contributors_url":"https://api.github.com/repos/docker/docker/contributors","subscribers_url":"https://api.github.com/repos/docker/docker/subscribers","subscription_url":"https://api.github.com/repos/docker/docker/subscription","commits_url":"https://api.github.com/repos/docker/docker/commits{/sha}","git_commits_url":"https://api.github.com/repos/docker/docker/git/commits{/sha}","comments_url":"https://api.github.com/repos/docker/docker/comments{/number}","issue_comment_url":"https://api.github.com/repos/docker/docker/issues/comments{/number}","contents_url":"https://api.github.com/repos/docker/docker/contents/{+path}","compare_url":"https://api.github.com/repos/docker/docker/compare/{base}...{head}","merges_url":"https://api.github.com/repos/docker/docker/merges","archive_url":"https://api.github.com/repos/docker/docker/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/docker/docker/downloads","issues_url":"https://api.github.com/repos/docker/docker/issues{/number}","pulls_url":"https://api.github.com/repos/docker/docker/pulls{/number}","milestones_url":"https://api.github.com/repos/docker/docker/milestones{/number}","notifications_url":"https://api.github.com/repos/docker/docker/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/docker/docker/labels{/name}","releases_url":"https://api.github.com/repos/docker/docker/releases{/id}","created_at":"2013-01-18T18:10:57Z","updated_at":"2015-09-15T13:40:15Z","pushed_at":"2015-09-15T13:35:18Z","git_url":"git://github.com/docker/docker.git","ssh_url":"git@github.com:docker/docker.git","clone_url":"https://github.com/docker/docker.git","svn_url":"https://github.com/docker/docker","homepage":"http://www.docker.com","size":251784,"stargazers_count":24756,"watchers_count":24756,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":6399,"mirror_url":null,"open_issues_count":1069,"forks":6399,"open_issues":1069,"watchers":24756,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/docker/docker/pulls/15069"},"html":{"href":"https://github.com/docker/docker/pull/15069"},"issue":{"href":"https://api.github.com/repos/docker/docker/issues/15069"},"comments":{"href":"https://api.github.com/repos/docker/docker/issues/15069/comments"},"review_comments":{"href":"https://api.github.com/repos/docker/docker/pulls/15069/comments"},"review_comment":{"href":"https://api.github.com/repos/docker/docker/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/docker/docker/pulls/15069/commits"},"statuses":{"href":"https://api.github.com/repos/docker/docker/statuses/628b9a41b09fde3ce1493f7d4f1495b9afaa506c"}}}}