{"action":"opened","issue":{"url":"https://api.github.com/repos/iron-meteor/iron-router/issues/1257","labels_url":"https://api.github.com/repos/iron-meteor/iron-router/issues/1257/labels{/name}","comments_url":"https://api.github.com/repos/iron-meteor/iron-router/issues/1257/comments","events_url":"https://api.github.com/repos/iron-meteor/iron-router/issues/1257/events","html_url":"https://github.com/iron-meteor/iron-router/issues/1257","id":59336457,"number":1257,"title":"API post request and catch/try","user":{"login":"Oyabi","id":7139283,"avatar_url":"https://avatars.githubusercontent.com/u/7139283?v=3","gravatar_id":"","url":"https://api.github.com/users/Oyabi","html_url":"https://github.com/Oyabi","followers_url":"https://api.github.com/users/Oyabi/followers","following_url":"https://api.github.com/users/Oyabi/following{/other_user}","gists_url":"https://api.github.com/users/Oyabi/gists{/gist_id}","starred_url":"https://api.github.com/users/Oyabi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Oyabi/subscriptions","organizations_url":"https://api.github.com/users/Oyabi/orgs","repos_url":"https://api.github.com/users/Oyabi/repos","events_url":"https://api.github.com/users/Oyabi/events{/privacy}","received_events_url":"https://api.github.com/users/Oyabi/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-02-28T10:24:27Z","updated_at":"2015-02-28T10:24:27Z","closed_at":null,"body":"I want to make an API in my application with a POST request. I want to pass json in my POST and try/catch the error if json is not parsable for not return error to my client.\r\n\r\nI have this code :\r\n\r\nRouter.map(function() {\r\n    this.route('data', {\r\n        path: '/data',\r\n        where: 'server',\r\n        action: function() {\r\n            // Data from a POST request\r\n            var requestData = this.request.body;\r\n\r\n\r\n            if(this.request.method == \"POST\"){\r\n              try{\r\n               JSON.stringify(requestData);\r\n              }catch(e){\r\n                //console.log(e);\r\n                if(e instanceof SyntaxError){\r\n                  this.response.writeHead(200, {'Content-Type': 'text/html$\r\n                  this.response.end('SyntaxError');\r\n                }\r\n              }\r\n            }\r\n            // Could be, e.g. application/xml, etc.\r\n           //this.response.end('<html><body>Your request was a ' + reques$\r\n       }\r\n    });\r\n});\r\n\r\nBut it's doesn't work when I got error in my JSON, my client (a simple bash script) receive an error (SyntaxError: Unexpected token C at Object.parse (native)) and I see this exception also in server.\r\n\r\nRegards.\r\n\r\nEDIT: it's work with well formatted JSON but not with mal formatted.\r\n"}}