{"action":"created","issue":{"url":"https://api.github.com/repos/meteor/meteor/issues/4478","labels_url":"https://api.github.com/repos/meteor/meteor/issues/4478/labels{/name}","comments_url":"https://api.github.com/repos/meteor/meteor/issues/4478/comments","events_url":"https://api.github.com/repos/meteor/meteor/issues/4478/events","html_url":"https://github.com/meteor/meteor/issues/4478","id":82743455,"number":4478,"title":"Meteor Style Guide Clarification Required Regarding Generating Error Messages","user":{"login":"lb-","id":1396140,"avatar_url":"https://avatars.githubusercontent.com/u/1396140?v=3","gravatar_id":"","url":"https://api.github.com/users/lb-","html_url":"https://github.com/lb-","followers_url":"https://api.github.com/users/lb-/followers","following_url":"https://api.github.com/users/lb-/following{/other_user}","gists_url":"https://api.github.com/users/lb-/gists{/gist_id}","starred_url":"https://api.github.com/users/lb-/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lb-/subscriptions","organizations_url":"https://api.github.com/users/lb-/orgs","repos_url":"https://api.github.com/users/lb-/repos","events_url":"https://api.github.com/users/lb-/events{/privacy}","received_events_url":"https://api.github.com/users/lb-/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/meteor/meteor/labels/Project:DDP","name":"Project:DDP","color":"c7def8"},{"url":"https://api.github.com/repos/meteor/meteor/labels/Project:Docs","name":"Project:Docs","color":"fbca04"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":10,"created_at":"2015-05-30T08:01:04Z","updated_at":"2015-06-06T02:08:44Z","closed_at":null,"body":"How do we reconcile the way you generate an error in a server method; `new Meteor.Error(error, [reason], [details])` with what is prescribed in the Meteor style guide:\r\n\r\n> Say you have a server method that can fail in one of three ways: \"No such user\", \"Site doesn't exist\", or \"Access denied\".\r\n>\r\n> Right: In the event of failure, the server returns a symbolic error code, 'no-such-user', 'site-not-found', or 'access-denied'. The client then looks up that error code in a table to get an appropriate message and displays it to the user.\r\n>\r\n> Wrong: The server returns an error string, such as \"No such user\", \"Site doesn't exist\", or \"Access denied\", which the client prints. This creates multiple problems. First, what if in the future the client wants to make a decision based on the error returned? (For example, a client might want to create the site if it doesn't exist, or try to log in as an administrator if access was denied.) Second, it complicates internationalization (the user's language code would have to be sent to the server so that it could return error messages in the appropriate language, requiring a protocol change, whereas constructing the error on the client does not block internationalization on a protocol change).\r\n>\r\n> Wrong: The server returns a HTTP-style status code and message, such as \"403 Access Denied\" or \"404 No Such User\". HTTP just doesn't define enough status codes for them to be a viable alternative to string codes like \"site-not-found\". For example, if 404 is used to represent the 'no-such-user' condition, what's left to represent 'site-not-found'?\r\n\r\nFrom https://github.com/meteor/meteor/wiki/Meteor-Style-Guide#generate-error-messages-on-the-client-not-on-the-server\r\n\r\n# Assumed Interpretation: Error is the 'symbolic error code'\r\n\r\n1. `error` - are we to assume this is the symbolic error code defined in the 'right' way to to do things?\r\n2. `reason` - this becomes useless, unless of course you wish to provide the third argument `details`\r\n\r\nExample\r\n```js\r\nif (Meteor.isServer) {\r\n  //server\r\n  Meteor.methods({\r\n    'messages.delete': function (messageId) {\r\n      check(messageId, String);\r\n      \r\n      if (!this.userId) {\r\n        throw new Meteor.Error('user-must-sign-in');\r\n      }\r\n      \r\n      if (!Messages.findOne(messageId)) {\r\n        throw new Meteor.Error('message-not-found');\r\n      }\r\n    }\r\n  });\r\n} else {\r\n  //client\r\n  errorMessages = {\r\n    'message-not-found': function () {\r\n      return {\r\n        title: 'Message Not Found',\r\n        text: 'Message was not found!',\r\n        type: 'error'\r\n      };\r\n    },\r\n    'user-must-sign-in': function () {\r\n      return {\r\n        title: 'Not Signed In',\r\n        text: 'Sorry, you must be signed in to to that!',\r\n        type: 'error'\r\n      };\r\n    },\r\n  }\r\n  \r\n  Meteor.call('messages.delete', someMessageId, function (error) {\r\n    // identify the error\r\n    if (error) {\r\n      myAlertGeneratingFunctionWithI18N(error.error);\r\n    }\r\n  });\r\n  \r\n}\r\n\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/meteor/meteor/issues/comments/109502697","html_url":"https://github.com/meteor/meteor/issues/4478#issuecomment-109502697","issue_url":"https://api.github.com/repos/meteor/meteor/issues/4478","id":109502697,"user":{"login":"lb-","id":1396140,"avatar_url":"https://avatars.githubusercontent.com/u/1396140?v=3","gravatar_id":"","url":"https://api.github.com/users/lb-","html_url":"https://github.com/lb-","followers_url":"https://api.github.com/users/lb-/followers","following_url":"https://api.github.com/users/lb-/following{/other_user}","gists_url":"https://api.github.com/users/lb-/gists{/gist_id}","starred_url":"https://api.github.com/users/lb-/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lb-/subscriptions","organizations_url":"https://api.github.com/users/lb-/orgs","repos_url":"https://api.github.com/users/lb-/repos","events_url":"https://api.github.com/users/lb-/events{/privacy}","received_events_url":"https://api.github.com/users/lb-/received_events","type":"User","site_admin":false},"created_at":"2015-06-06T02:08:44Z","updated_at":"2015-06-06T02:08:44Z","body":"Just found this (related to above comment about gRPC) but the error codes appear to be very high level and may not suit the issue that we are trying to solve.\r\n\r\nhttps://github.com/grpc/grpc-common/blob/1b1b826628661f13caa0af59171a874225634f4b/PROTOCOL-HTTP2.md#errors\r\n\r\n"}}