{"action":"created","issue":{"url":"https://api.github.com/repos/graphcool/api-bugs/issues/221","repository_url":"https://api.github.com/repos/graphcool/api-bugs","labels_url":"https://api.github.com/repos/graphcool/api-bugs/issues/221/labels{/name}","comments_url":"https://api.github.com/repos/graphcool/api-bugs/issues/221/comments","events_url":"https://api.github.com/repos/graphcool/api-bugs/issues/221/events","html_url":"https://github.com/graphcool/api-bugs/issues/221","id":248246675,"number":221,"title":"SE returns stringified JSON error object","user":{"login":"kbrandwijk","id":852069,"avatar_url":"https://avatars1.githubusercontent.com/u/852069?v=4","gravatar_id":"","url":"https://api.github.com/users/kbrandwijk","html_url":"https://github.com/kbrandwijk","followers_url":"https://api.github.com/users/kbrandwijk/followers","following_url":"https://api.github.com/users/kbrandwijk/following{/other_user}","gists_url":"https://api.github.com/users/kbrandwijk/gists{/gist_id}","starred_url":"https://api.github.com/users/kbrandwijk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kbrandwijk/subscriptions","organizations_url":"https://api.github.com/users/kbrandwijk/orgs","repos_url":"https://api.github.com/users/kbrandwijk/repos","events_url":"https://api.github.com/users/kbrandwijk/events{/privacy}","received_events_url":"https://api.github.com/users/kbrandwijk/received_events","type":"User","site_admin":false},"labels":[{"id":623806975,"url":"https://api.github.com/repos/graphcool/api-bugs/labels/area/functions","name":"area/functions","color":"fbca04","default":false},{"id":653820283,"url":"https://api.github.com/repos/graphcool/api-bugs/labels/beta","name":"beta","color":"cc317c","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2017-08-06T13:17:11Z","updated_at":"2017-08-07T16:11:03Z","closed_at":null,"body":"**What is the current behavior?**\r\nWhen returning an error object from a function, according to https://www.graph.cool/docs/reference/functions/error-handling-quawa7aed0/#returning-error-objects, the error is returned as JSON. For SE, this JSON is returned as a string instead. Also, the root 'error' object, specified in the documentation, is missing.\r\n\r\n```graphql\r\n{\r\n  \"data\": {\r\n    \"getWeatherByCity\": null\r\n  },\r\n  \"errors\": [\r\n    {\r\n      \"locations\": [\r\n        {\r\n          \"line\": 2,\r\n          \"column\": 3\r\n        }\r\n      ],\r\n      \"functionError\": \"{\\\"cod\\\":\\\"404\\\",\\\"message\\\":\\\"city not found\\\"}\",\r\n      \"path\": [\r\n        \"getWeatherByCity\"\r\n      ],\r\n      \"code\": 5002,\r\n      \"message\": \"function execution error\",\r\n      \"requestId\": \"simple:cj60qty4l3zw80169xoxhhqzl\"\r\n    }\r\n  ]\r\n}\r\n```\r\n\r\n**What is the expected behavior?**\r\nError object returned as JSON.\r\n\r\n```graphql\r\n{\r\n  \"data\": {\r\n    \"getWeatherByCity\": null\r\n  },\r\n  \"errors\": [\r\n    {\r\n      \"locations\": [\r\n        {\r\n          \"line\": 2,\r\n          \"column\": 3\r\n        }\r\n      ],\r\n      \"functionError\": { \r\n        \"error\": {\r\n          \"cod\": 404,\r\n          \"message\": \"city not found\"\r\n        }\r\n      },\r\n      \"path\": [\r\n        \"getWeatherByCity\"\r\n      ],\r\n      \"code\": 5002,\r\n      \"message\": \"function execution error\",\r\n      \"requestId\": \"simple:cj60qty4l3zw80169xoxhhqzl\"\r\n    }\r\n  ]\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/graphcool/api-bugs/issues/comments/320707895","html_url":"https://github.com/graphcool/api-bugs/issues/221#issuecomment-320707895","issue_url":"https://api.github.com/repos/graphcool/api-bugs/issues/221","id":320707895,"user":{"login":"sorenbs","id":281337,"avatar_url":"https://avatars3.githubusercontent.com/u/281337?v=4","gravatar_id":"","url":"https://api.github.com/users/sorenbs","html_url":"https://github.com/sorenbs","followers_url":"https://api.github.com/users/sorenbs/followers","following_url":"https://api.github.com/users/sorenbs/following{/other_user}","gists_url":"https://api.github.com/users/sorenbs/gists{/gist_id}","starred_url":"https://api.github.com/users/sorenbs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sorenbs/subscriptions","organizations_url":"https://api.github.com/users/sorenbs/orgs","repos_url":"https://api.github.com/users/sorenbs/repos","events_url":"https://api.github.com/users/sorenbs/events{/privacy}","received_events_url":"https://api.github.com/users/sorenbs/received_events","type":"User","site_admin":false},"created_at":"2017-08-07T16:11:03Z","updated_at":"2017-08-07T16:11:03Z","body":"@marktani The extra `error` root is a mistake in the documentation. It should be like this instead:\r\n\r\n```json\r\n{\r\n  \"data\": null,\r\n  \"errors\": [\r\n    {\r\n      \"code\": 5002,\r\n      \"message\": \"Function execution error\",\r\n      \"functionError\": {\r\n// no error here\r\n          \"code\": 42,\r\n          \"message\": \"Invalid email!\",\r\n          \"debugMessage\": \"We should add validation in the frontend as well!\",\r\n          \"userFacingMessage\": \"Please supply a valid email address!\"\r\n      }\r\n    }\r\n  ]\r\n}\r\n```"}}
{"actor":{"display_login":"sorenbs"}}