GitHub PullRequestReviewCommentEvent at 2014-01-31 17:39:59
Repository: badgekit-issue
Actor: andrewhayward
Payload: {"comment":{"url":"https://api.github.com/repos/mozilla/badgekit-issue/pulls/comments/9350302","id":9350302,"diff_hunk":"@@ -0,0 +1,39 @@\n+module.exports = {\n+  validation: validationHelper,\n+  makeDbHandler: makeDbHandler,\n+  notFound: notFound,\n+}\n+\n+const restify = require('restify')\n+\n+function validationHelper(errors) {\n+  return {\n+    code: 'ValidationError',\n+    message: 'Could not validate required fields',\n+    details: errors,\n+  }\n+}\n+\n+function notFound(message) {\n+  return new restify.ResourceNotFoundError(message)\n+}\n+\n+function makeDbHandler(modelName) {\n+  const errorCodes = {\n+    ER_DUP_ENTRY: [409, {code: 'ResourceConflict', message: modelName + ' with that `slug` already exists'}]\n+  }\n+\n+  function knownError(error, row) {\n+    const err = errorCodes[error.code];\n+    if (!err) return;\n+    if (row) err[1].details = row\n+    return err;\n+  }\n+\n+  return function handleError(error, row, res, next) {\n+    const expected = knownError(error, row)\n+    if (!expected) return next(error)","path":"app/lib/error-helper.js","position":35,"original_position":35,"commit_id":"c5266c6cd186befca48f8852e1e48b9f9bd363e6","original_commit_id":"c5266c6cd186befca48f8852e1e48b9f9bd363e6","user":{"login":"andrewhayward","id":159848,"avatar_url":"https://gravatar.com/avatar/8c9517be4c7cbb31f94d1a6a5e0dc09e?d=https%3A%2F%2Fidenticons.github.com%2F6ed977ec1a28f6703b401ed4db8305a6.png&r=x","gravatar_id":"8c9517be4c7cbb31f94d1a6a5e0dc09e","url":"https://api.github.com/users/andrewhayward","html_url":"https://github.com/andrewhayward","followers_url":"https://api.github.com/users/andrewhayward/followers","following_url":"https://api.github.com/users/andrewhayward/following{/other_user}","gists_url":"https://api.github.com/users/andrewhayward/gists{/gist_id}","starred_url":"https://api.github.com/users/andrewhayward/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andrewhayward/subscriptions","organizations_url":"https://api.github.com/users/andrewhayward/orgs","repos_url":"https://api.github.com/users/andrewhayward/repos","events_url":"https://api.github.com/users/andrewhayward/events{/privacy}","received_events_url":"https://api.github.com/users/andrewhayward/received_events","type":"User","site_admin":false},"body":"Are unrecognised database errors being handled anywhere in a way that would result in something meaningful (that is, a restify style structure) being sent back to the client? Based on this line, it would seem not, but wondering if there's anything further along the line that handles standard errors.","created_at":"2014-01-31T17:39:59Z","updated_at":"2014-01-31T17:39:59Z","html_url":"https://github.com/mozilla/badgekit-issue/pull/18#discussion_r9350302","pull_request_url":"https://api.github.com/repos/mozilla/badgekit-issue/pulls/18","_links":{"self":{"href":"https://api.github.com/repos/mozilla/badgekit-issue/pulls/comments/9350302"},"html":{"href":"https://github.com/mozilla/badgekit-issue/pull/18#discussion_r9350302"},"pull_request":{"href":"https://api.github.com/repos/mozilla/badgekit-issue/pulls/18"}}}}