{"action":"created","issue":{"url":"https://api.github.com/repos/bufferapp/buffer-rpc/issues/5","repository_url":"https://api.github.com/repos/bufferapp/buffer-rpc","labels_url":"https://api.github.com/repos/bufferapp/buffer-rpc/issues/5/labels{/name}","comments_url":"https://api.github.com/repos/bufferapp/buffer-rpc/issues/5/comments","events_url":"https://api.github.com/repos/bufferapp/buffer-rpc/issues/5/events","html_url":"https://github.com/bufferapp/buffer-rpc/issues/5","id":368380417,"node_id":"MDU6SXNzdWUzNjgzODA0MTc=","number":5,"title":"Using custom Error types for consistency and brevity in error status codes","user":{"login":"djfarrelly","id":1509457,"node_id":"MDQ6VXNlcjE1MDk0NTc=","avatar_url":"https://avatars0.githubusercontent.com/u/1509457?v=4","gravatar_id":"","url":"https://api.github.com/users/djfarrelly","html_url":"https://github.com/djfarrelly","followers_url":"https://api.github.com/users/djfarrelly/followers","following_url":"https://api.github.com/users/djfarrelly/following{/other_user}","gists_url":"https://api.github.com/users/djfarrelly/gists{/gist_id}","starred_url":"https://api.github.com/users/djfarrelly/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/djfarrelly/subscriptions","organizations_url":"https://api.github.com/users/djfarrelly/orgs","repos_url":"https://api.github.com/users/djfarrelly/repos","events_url":"https://api.github.com/users/djfarrelly/events{/privacy}","received_events_url":"https://api.github.com/users/djfarrelly/received_events","type":"User","site_admin":false},"labels":[{"id":1046854179,"node_id":"MDU6TGFiZWwxMDQ2ODU0MTc5","url":"https://api.github.com/repos/bufferapp/buffer-rpc/labels/enhancement","name":"enhancement","color":"a2eeef","default":true}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-10-09T20:20:40Z","updated_at":"2019-05-15T09:19:19Z","closed_at":null,"author_association":"MEMBER","body":"_Copied from https://github.com/bufferapp/micro-rpc/issues/2_\r\n\r\n### Purpose\r\nInspired by [Apollo server's way to throw errors](https://www.apollographql.com/docs/apollo-server/features/errors.html#Codes), I was thinking it might be a little nicer than the current `createError` pattern.\r\n\r\n### Proposal\r\nInstead of creating the error and optionally pass an error code, we have specific errors that consumers can import which might make things consistent.\r\n```js\r\nconst {\r\n  rpc,\r\n  method,\r\n  ParameterError,  // or UserInputError like Apollo\r\n  ForbiddenError,\r\n  FatalError,\r\n} = require('@bufferapp/micro-rpc');\r\n\r\nmodule.exports = rpc(\r\n  method('getUser', async ({ _id }) => {\r\n    if (!accessToken || isValidAccessToken(accessToken)) {\r\n      throw new ForbiddenError()\r\n      // response => 403 { message: 'Forbidden' }\r\n    }\r\n    if (!_id) {\r\n      throw new ParameterError(`_id required`)\r\n      // response => 400 { message: '_id required' }\r\n    }\r\n    if (!isValidID(_id)) {\r\n      throw new ParameterError('Invalid _id parameter')\r\n      // response => 400 { message: 'Invalid _id parameter' }\r\n    }\r\n    try {\r\n      const user = db.\r\n    } catch (err) {\r\n      throw new FatalError(`Database error finding user ${_id}`)\r\n      // response => 500 { message: '_id required' }\r\n    }\r\n  })\r\n)\r\n```\r\nThese errors would already have the err.statusCode set. \r\n\r\nThis also could help us remove this library's dependency on `micro` or we could use this pattern to create a new `micro`-less rpc library since we're using Express under the hood."},"comment":{"url":"https://api.github.com/repos/bufferapp/buffer-rpc/issues/comments/492575888","html_url":"https://github.com/bufferapp/buffer-rpc/issues/5#issuecomment-492575888","issue_url":"https://api.github.com/repos/bufferapp/buffer-rpc/issues/5","id":492575888,"node_id":"MDEyOklzc3VlQ29tbWVudDQ5MjU3NTg4OA==","user":{"login":"msanroman","id":720667,"node_id":"MDQ6VXNlcjcyMDY2Nw==","avatar_url":"https://avatars3.githubusercontent.com/u/720667?v=4","gravatar_id":"","url":"https://api.github.com/users/msanroman","html_url":"https://github.com/msanroman","followers_url":"https://api.github.com/users/msanroman/followers","following_url":"https://api.github.com/users/msanroman/following{/other_user}","gists_url":"https://api.github.com/users/msanroman/gists{/gist_id}","starred_url":"https://api.github.com/users/msanroman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/msanroman/subscriptions","organizations_url":"https://api.github.com/users/msanroman/orgs","repos_url":"https://api.github.com/users/msanroman/repos","events_url":"https://api.github.com/users/msanroman/events{/privacy}","received_events_url":"https://api.github.com/users/msanroman/received_events","type":"User","site_admin":false},"created_at":"2019-05-15T09:19:19Z","updated_at":"2019-05-15T09:19:19Z","author_association":"MEMBER","body":"I love it! :+1:"}}
{"actor":{"display_login":"msanroman"}}