{"action":"created","comment":{"url":"https://api.github.com/repos/stubailo/meteor-rest/pulls/comments/30655010","id":30655010,"diff_hunk":"@@ -55,15 +55,60 @@ var setHeaders = function (res) {\n   });\n };\n \n+var defaultConfig = {\n+  prettyPrintResponses: false\n+};\n+\n+var config = defaultConfig;\n+JsonRoutes.config = function (userConfig) {\n+  config = _.extend({}, defaultConfig, userConfig);\n+};\n+\n+/**\n+ * Sets the response headers, status code, and body, and ends it. The JSON response will be pretty printed if NODE_ENV is `development` or if you have configured `prettyPrintResponses: true`.\n+ * @param {Object}   res  Response object\n+ * @param {Number}   code HTTP status code. If `json` argument is an `Error` object, this will be overwritten based on the error.\n+ * @param {Object|Array|null|undefined|Error} json The object to stringify as the response. If `null`, the response will be \"null\". If `undefined`, there will be no response body. If an `Error` type, a JSON representation of the error details will be sent.\n+ */\n JsonRoutes.sendResult = function (res, code, json) {\n   setHeaders(res);\n+\n+  // Convert `Error` objects to JSON representations\n+  if (json) {\n+    if (json instanceof Meteor.Error) {","path":"packages/json-routes/json-routes.js","position":null,"original_position":24,"commit_id":"ac60d181bf2b084e96151554df909079d4197ac9","original_commit_id":"4e24d060353bbf60e3d582052b465b865f66dad3","user":{"login":"aldeed","id":3012067,"avatar_url":"https://avatars.githubusercontent.com/u/3012067?v=3","gravatar_id":"","url":"https://api.github.com/users/aldeed","html_url":"https://github.com/aldeed","followers_url":"https://api.github.com/users/aldeed/followers","following_url":"https://api.github.com/users/aldeed/following{/other_user}","gists_url":"https://api.github.com/users/aldeed/gists{/gist_id}","starred_url":"https://api.github.com/users/aldeed/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aldeed/subscriptions","organizations_url":"https://api.github.com/users/aldeed/orgs","repos_url":"https://api.github.com/users/aldeed/repos","events_url":"https://api.github.com/users/aldeed/events{/privacy}","received_events_url":"https://api.github.com/users/aldeed/received_events","type":"User","site_admin":false},"body":"Done","created_at":"2015-05-19T22:30:04Z","updated_at":"2015-05-19T22:30:04Z","html_url":"https://github.com/stubailo/meteor-rest/pull/22#discussion_r30655010","pull_request_url":"https://api.github.com/repos/stubailo/meteor-rest/pulls/22","_links":{"self":{"href":"https://api.github.com/repos/stubailo/meteor-rest/pulls/comments/30655010"},"html":{"href":"https://github.com/stubailo/meteor-rest/pull/22#discussion_r30655010"},"pull_request":{"href":"https://api.github.com/repos/stubailo/meteor-rest/pulls/22"}}},"pull_request":{"url":"https://api.github.com/repos/stubailo/meteor-rest/pulls/22","id":35743911,"html_url":"https://github.com/stubailo/meteor-rest/pull/22","diff_url":"https://github.com/stubailo/meteor-rest/pull/22.diff","patch_url":"https://github.com/stubailo/meteor-rest/pull/22.patch","issue_url":"https://api.github.com/repos/stubailo/meteor-rest/issues/22","number":22,"state":"open","locked":false,"title":"Better error responses","user":{"login":"aldeed","id":3012067,"avatar_url":"https://avatars.githubusercontent.com/u/3012067?v=3","gravatar_id":"","url":"https://api.github.com/users/aldeed","html_url":"https://github.com/aldeed","followers_url":"https://api.github.com/users/aldeed/followers","following_url":"https://api.github.com/users/aldeed/following{/other_user}","gists_url":"https://api.github.com/users/aldeed/gists{/gist_id}","starred_url":"https://api.github.com/users/aldeed/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aldeed/subscriptions","organizations_url":"https://api.github.com/users/aldeed/orgs","repos_url":"https://api.github.com/users/aldeed/repos","events_url":"https://api.github.com/users/aldeed/events{/privacy}","received_events_url":"https://api.github.com/users/aldeed/received_events","type":"User","site_admin":false},"body":"* Add ability for `data` argument of `sendResult` to be an `Error`\r\n* Add `JsonRoutes.config` and ability to force pretty printing of all responses\r\n\r\n@stubailo this is part 1 of improving and simplifying sending errors. The next thing I'd like to do is add the ability to register a custom errorToJson function. Then I can update the simple-schema package to register one that adds the full list of schema errors to the error JSON.\r\n\r\nEnd goal is to be able to do this:\r\n\r\n```js\r\nMeteor.methods({\r\n  foo: function (obj) {\r\n    check(obj, objSchema);\r\n  }\r\n});\r\n```\r\n\r\nAnd get full schema validation info in the response object. I think this will also automatically work for POST/PATCH on collections that have a schema attached via collection2 package.\r\n\r\nLet me know your thoughts. Thanks!","created_at":"2015-05-19T15:39:39Z","updated_at":"2015-05-19T22:30:04Z","closed_at":null,"merged_at":null,"merge_commit_sha":"cc4c962de7ac6f549c523f98ef0f85f039731730","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/stubailo/meteor-rest/pulls/22/commits","review_comments_url":"https://api.github.com/repos/stubailo/meteor-rest/pulls/22/comments","review_comment_url":"https://api.github.com/repos/stubailo/meteor-rest/pulls/comments{/number}","comments_url":"https://api.github.com/repos/stubailo/meteor-rest/issues/22/comments","statuses_url":"https://api.github.com/repos/stubailo/meteor-rest/statuses/ac60d181bf2b084e96151554df909079d4197ac9","head":{"label":"aldeed:better-errors","ref":"better-errors","sha":"ac60d181bf2b084e96151554df909079d4197ac9","user":{"login":"aldeed","id":3012067,"avatar_url":"https://avatars.githubusercontent.com/u/3012067?v=3","gravatar_id":"","url":"https://api.github.com/users/aldeed","html_url":"https://github.com/aldeed","followers_url":"https://api.github.com/users/aldeed/followers","following_url":"https://api.github.com/users/aldeed/following{/other_user}","gists_url":"https://api.github.com/users/aldeed/gists{/gist_id}","starred_url":"https://api.github.com/users/aldeed/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aldeed/subscriptions","organizations_url":"https://api.github.com/users/aldeed/orgs","repos_url":"https://api.github.com/users/aldeed/repos","events_url":"https://api.github.com/users/aldeed/events{/privacy}","received_events_url":"https://api.github.com/users/aldeed/received_events","type":"User","site_admin":false},"repo":{"id":35226781,"name":"meteor-rest","full_name":"aldeed/meteor-rest","owner":{"login":"aldeed","id":3012067,"avatar_url":"https://avatars.githubusercontent.com/u/3012067?v=3","gravatar_id":"","url":"https://api.github.com/users/aldeed","html_url":"https://github.com/aldeed","followers_url":"https://api.github.com/users/aldeed/followers","following_url":"https://api.github.com/users/aldeed/following{/other_user}","gists_url":"https://api.github.com/users/aldeed/gists{/gist_id}","starred_url":"https://api.github.com/users/aldeed/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aldeed/subscriptions","organizations_url":"https://api.github.com/users/aldeed/orgs","repos_url":"https://api.github.com/users/aldeed/repos","events_url":"https://api.github.com/users/aldeed/events{/privacy}","received_events_url":"https://api.github.com/users/aldeed/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/aldeed/meteor-rest","description":"simple:rest - automatically make your Meteor app accessible over HTTP and DDP alike","fork":true,"url":"https://api.github.com/repos/aldeed/meteor-rest","forks_url":"https://api.github.com/repos/aldeed/meteor-rest/forks","keys_url":"https://api.github.com/repos/aldeed/meteor-rest/keys{/key_id}","collaborators_url":"https://api.github.com/repos/aldeed/meteor-rest/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/aldeed/meteor-rest/teams","hooks_url":"https://api.github.com/repos/aldeed/meteor-rest/hooks","issue_events_url":"https://api.github.com/repos/aldeed/meteor-rest/issues/events{/number}","events_url":"https://api.github.com/repos/aldeed/meteor-rest/events","assignees_url":"https://api.github.com/repos/aldeed/meteor-rest/assignees{/user}","branches_url":"https://api.github.com/repos/aldeed/meteor-rest/branches{/branch}","tags_url":"https://api.github.com/repos/aldeed/meteor-rest/tags","blobs_url":"https://api.github.com/repos/aldeed/meteor-rest/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/aldeed/meteor-rest/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/aldeed/meteor-rest/git/refs{/sha}","trees_url":"https://api.github.com/repos/aldeed/meteor-rest/git/trees{/sha}","statuses_url":"https://api.github.com/repos/aldeed/meteor-rest/statuses/{sha}","languages_url":"https://api.github.com/repos/aldeed/meteor-rest/languages","stargazers_url":"https://api.github.com/repos/aldeed/meteor-rest/stargazers","contributors_url":"https://api.github.com/repos/aldeed/meteor-rest/contributors","subscribers_url":"https://api.github.com/repos/aldeed/meteor-rest/subscribers","subscription_url":"https://api.github.com/repos/aldeed/meteor-rest/subscription","commits_url":"https://api.github.com/repos/aldeed/meteor-rest/commits{/sha}","git_commits_url":"https://api.github.com/repos/aldeed/meteor-rest/git/commits{/sha}","comments_url":"https://api.github.com/repos/aldeed/meteor-rest/comments{/number}","issue_comment_url":"https://api.github.com/repos/aldeed/meteor-rest/issues/comments{/number}","contents_url":"https://api.github.com/repos/aldeed/meteor-rest/contents/{+path}","compare_url":"https://api.github.com/repos/aldeed/meteor-rest/compare/{base}...{head}","merges_url":"https://api.github.com/repos/aldeed/meteor-rest/merges","archive_url":"https://api.github.com/repos/aldeed/meteor-rest/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/aldeed/meteor-rest/downloads","issues_url":"https://api.github.com/repos/aldeed/meteor-rest/issues{/number}","pulls_url":"https://api.github.com/repos/aldeed/meteor-rest/pulls{/number}","milestones_url":"https://api.github.com/repos/aldeed/meteor-rest/milestones{/number}","notifications_url":"https://api.github.com/repos/aldeed/meteor-rest/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/aldeed/meteor-rest/labels{/name}","releases_url":"https://api.github.com/repos/aldeed/meteor-rest/releases{/id}","created_at":"2015-05-07T15:05:51Z","updated_at":"2015-05-07T15:05:51Z","pushed_at":"2015-05-19T22:29:59Z","git_url":"git://github.com/aldeed/meteor-rest.git","ssh_url":"git@github.com:aldeed/meteor-rest.git","clone_url":"https://github.com/aldeed/meteor-rest.git","svn_url":"https://github.com/aldeed/meteor-rest","homepage":"https://atmospherejs.com/simple/rest","size":185,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","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":"stubailo:master","ref":"master","sha":"17ab492cd8d9d1355d9e2630821a01d3f12d9357","user":{"login":"stubailo","id":448783,"avatar_url":"https://avatars.githubusercontent.com/u/448783?v=3","gravatar_id":"","url":"https://api.github.com/users/stubailo","html_url":"https://github.com/stubailo","followers_url":"https://api.github.com/users/stubailo/followers","following_url":"https://api.github.com/users/stubailo/following{/other_user}","gists_url":"https://api.github.com/users/stubailo/gists{/gist_id}","starred_url":"https://api.github.com/users/stubailo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stubailo/subscriptions","organizations_url":"https://api.github.com/users/stubailo/orgs","repos_url":"https://api.github.com/users/stubailo/repos","events_url":"https://api.github.com/users/stubailo/events{/privacy}","received_events_url":"https://api.github.com/users/stubailo/received_events","type":"User","site_admin":false},"repo":{"id":34431164,"name":"meteor-rest","full_name":"stubailo/meteor-rest","owner":{"login":"stubailo","id":448783,"avatar_url":"https://avatars.githubusercontent.com/u/448783?v=3","gravatar_id":"","url":"https://api.github.com/users/stubailo","html_url":"https://github.com/stubailo","followers_url":"https://api.github.com/users/stubailo/followers","following_url":"https://api.github.com/users/stubailo/following{/other_user}","gists_url":"https://api.github.com/users/stubailo/gists{/gist_id}","starred_url":"https://api.github.com/users/stubailo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stubailo/subscriptions","organizations_url":"https://api.github.com/users/stubailo/orgs","repos_url":"https://api.github.com/users/stubailo/repos","events_url":"https://api.github.com/users/stubailo/events{/privacy}","received_events_url":"https://api.github.com/users/stubailo/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/stubailo/meteor-rest","description":"simple:rest - automatically make your Meteor app accessible over HTTP and DDP alike","fork":false,"url":"https://api.github.com/repos/stubailo/meteor-rest","forks_url":"https://api.github.com/repos/stubailo/meteor-rest/forks","keys_url":"https://api.github.com/repos/stubailo/meteor-rest/keys{/key_id}","collaborators_url":"https://api.github.com/repos/stubailo/meteor-rest/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/stubailo/meteor-rest/teams","hooks_url":"https://api.github.com/repos/stubailo/meteor-rest/hooks","issue_events_url":"https://api.github.com/repos/stubailo/meteor-rest/issues/events{/number}","events_url":"https://api.github.com/repos/stubailo/meteor-rest/events","assignees_url":"https://api.github.com/repos/stubailo/meteor-rest/assignees{/user}","branches_url":"https://api.github.com/repos/stubailo/meteor-rest/branches{/branch}","tags_url":"https://api.github.com/repos/stubailo/meteor-rest/tags","blobs_url":"https://api.github.com/repos/stubailo/meteor-rest/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/stubailo/meteor-rest/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/stubailo/meteor-rest/git/refs{/sha}","trees_url":"https://api.github.com/repos/stubailo/meteor-rest/git/trees{/sha}","statuses_url":"https://api.github.com/repos/stubailo/meteor-rest/statuses/{sha}","languages_url":"https://api.github.com/repos/stubailo/meteor-rest/languages","stargazers_url":"https://api.github.com/repos/stubailo/meteor-rest/stargazers","contributors_url":"https://api.github.com/repos/stubailo/meteor-rest/contributors","subscribers_url":"https://api.github.com/repos/stubailo/meteor-rest/subscribers","subscription_url":"https://api.github.com/repos/stubailo/meteor-rest/subscription","commits_url":"https://api.github.com/repos/stubailo/meteor-rest/commits{/sha}","git_commits_url":"https://api.github.com/repos/stubailo/meteor-rest/git/commits{/sha}","comments_url":"https://api.github.com/repos/stubailo/meteor-rest/comments{/number}","issue_comment_url":"https://api.github.com/repos/stubailo/meteor-rest/issues/comments{/number}","contents_url":"https://api.github.com/repos/stubailo/meteor-rest/contents/{+path}","compare_url":"https://api.github.com/repos/stubailo/meteor-rest/compare/{base}...{head}","merges_url":"https://api.github.com/repos/stubailo/meteor-rest/merges","archive_url":"https://api.github.com/repos/stubailo/meteor-rest/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/stubailo/meteor-rest/downloads","issues_url":"https://api.github.com/repos/stubailo/meteor-rest/issues{/number}","pulls_url":"https://api.github.com/repos/stubailo/meteor-rest/pulls{/number}","milestones_url":"https://api.github.com/repos/stubailo/meteor-rest/milestones{/number}","notifications_url":"https://api.github.com/repos/stubailo/meteor-rest/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/stubailo/meteor-rest/labels{/name}","releases_url":"https://api.github.com/repos/stubailo/meteor-rest/releases{/id}","created_at":"2015-04-23T03:20:44Z","updated_at":"2015-05-19T03:16:14Z","pushed_at":"2015-05-19T22:29:59Z","git_url":"git://github.com/stubailo/meteor-rest.git","ssh_url":"git@github.com:stubailo/meteor-rest.git","clone_url":"https://github.com/stubailo/meteor-rest.git","svn_url":"https://github.com/stubailo/meteor-rest","homepage":"https://atmospherejs.com/simple/rest","size":479,"stargazers_count":67,"watchers_count":67,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":8,"mirror_url":null,"open_issues_count":9,"forks":8,"open_issues":9,"watchers":67,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/stubailo/meteor-rest/pulls/22"},"html":{"href":"https://github.com/stubailo/meteor-rest/pull/22"},"issue":{"href":"https://api.github.com/repos/stubailo/meteor-rest/issues/22"},"comments":{"href":"https://api.github.com/repos/stubailo/meteor-rest/issues/22/comments"},"review_comments":{"href":"https://api.github.com/repos/stubailo/meteor-rest/pulls/22/comments"},"review_comment":{"href":"https://api.github.com/repos/stubailo/meteor-rest/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/stubailo/meteor-rest/pulls/22/commits"},"statuses":{"href":"https://api.github.com/repos/stubailo/meteor-rest/statuses/ac60d181bf2b084e96151554df909079d4197ac9"}}}}