{"action":"created","issue":{"url":"https://api.github.com/repos/serverless/serverless/issues/608","repository_url":"https://api.github.com/repos/serverless/serverless","labels_url":"https://api.github.com/repos/serverless/serverless/issues/608/labels{/name}","comments_url":"https://api.github.com/repos/serverless/serverless/issues/608/comments","events_url":"https://api.github.com/repos/serverless/serverless/issues/608/events","html_url":"https://github.com/serverless/serverless/issues/608","id":132913589,"number":608,"title":"Add default error codes","user":{"login":"eahefnawy","id":2312463,"avatar_url":"https://avatars.githubusercontent.com/u/2312463?v=3","gravatar_id":"","url":"https://api.github.com/users/eahefnawy","html_url":"https://github.com/eahefnawy","followers_url":"https://api.github.com/users/eahefnawy/followers","following_url":"https://api.github.com/users/eahefnawy/following{/other_user}","gists_url":"https://api.github.com/users/eahefnawy/gists{/gist_id}","starred_url":"https://api.github.com/users/eahefnawy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eahefnawy/subscriptions","organizations_url":"https://api.github.com/users/eahefnawy/orgs","repos_url":"https://api.github.com/users/eahefnawy/repos","events_url":"https://api.github.com/users/eahefnawy/events{/privacy}","received_events_url":"https://api.github.com/users/eahefnawy/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/serverless/serverless/labels/enhancement","name":"enhancement","color":"009800"}],"state":"open","locked":false,"assignee":{"login":"eahefnawy","id":2312463,"avatar_url":"https://avatars.githubusercontent.com/u/2312463?v=3","gravatar_id":"","url":"https://api.github.com/users/eahefnawy","html_url":"https://github.com/eahefnawy","followers_url":"https://api.github.com/users/eahefnawy/followers","following_url":"https://api.github.com/users/eahefnawy/following{/other_user}","gists_url":"https://api.github.com/users/eahefnawy/gists{/gist_id}","starred_url":"https://api.github.com/users/eahefnawy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eahefnawy/subscriptions","organizations_url":"https://api.github.com/users/eahefnawy/orgs","repos_url":"https://api.github.com/users/eahefnawy/repos","events_url":"https://api.github.com/users/eahefnawy/events{/privacy}","received_events_url":"https://api.github.com/users/eahefnawy/received_events","type":"User","site_admin":false},"milestone":null,"comments":10,"created_at":"2016-02-11T08:12:28Z","updated_at":"2016-02-17T01:02:05Z","closed_at":null,"body":"Thanks to the awesome @staceymoore, we should now have the following default error codes templates in all projects `s-templates.json` file:\r\n\r\n```\r\n\"responsesForGet\": {\r\n    \".*400.*\": \"$${response400}\",\r\n    \".*Process exited.*\": \"$${response500}\",\r\n    \".*Task timed out.*\": \"$${response504}\",\r\n    \"default\": \"$${response200}\"\r\n  },\r\n  \"responsesForPost\": {\r\n    \".*400.*\": \"$${response400}\",\r\n    \".*Process exited.*\": \"$${response500}\",\r\n    \".*Task timed out.*\": \"$${response504}\",\r\n    \"default\": \"$${response201}\"\r\n  },\r\n  \"response200\": {\r\n    \"statusCode\": \"200\",\r\n    \"responseParameters\": \"$${responseParameters}\",\r\n    \"responseTemplates\": {\r\n      \"application/json\": \"\"\r\n    }\r\n  },\r\n  \"response201\": {\r\n    \"statusCode\": \"201\",\r\n    \"responseParameters\": \"$${responseParameters}\",\r\n    \"responseTemplates\": {\r\n      \"application/json\": \"\"\r\n    }\r\n  },\r\n  \"response400\": {\r\n    \"statusCode\": \"400\",\r\n    \"responseModels\": {},\r\n    \"responseTemplates\": {\r\n      \"application/json\": \"#set($inputRoot = $input.path('$.errorMessage'))$inputRoot\"\r\n    }\r\n  },\r\n  \"response500\": {\r\n    \"statusCode\": \"500\",\r\n    \"responseTemplates\": {\r\n      \"application/json\": \"{\\\"error\\\": \\\"Server Error\\\"}\"\r\n    }\r\n  },\r\n  \"response504\": {\r\n    \"statusCode\": \"504\",\r\n    \"responseTemplates\": {\r\n      \"application/json\": \"{\\\"error\\\": \\\"Gateway Timeout\\\"}\"\r\n    }\r\n  },\r\n  \"responseParameters\": {\r\n    \"method.response.header.location\": \"integration.response.body.links.self\"\r\n  }\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/serverless/serverless/issues/comments/184954698","html_url":"https://github.com/serverless/serverless/issues/608#issuecomment-184954698","issue_url":"https://api.github.com/repos/serverless/serverless/issues/608","id":184954698,"user":{"login":"erikerikson","id":571200,"avatar_url":"https://avatars.githubusercontent.com/u/571200?v=3","gravatar_id":"","url":"https://api.github.com/users/erikerikson","html_url":"https://github.com/erikerikson","followers_url":"https://api.github.com/users/erikerikson/followers","following_url":"https://api.github.com/users/erikerikson/following{/other_user}","gists_url":"https://api.github.com/users/erikerikson/gists{/gist_id}","starred_url":"https://api.github.com/users/erikerikson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/erikerikson/subscriptions","organizations_url":"https://api.github.com/users/erikerikson/orgs","repos_url":"https://api.github.com/users/erikerikson/repos","events_url":"https://api.github.com/users/erikerikson/events{/privacy}","received_events_url":"https://api.github.com/users/erikerikson/received_events","type":"User","site_admin":false},"created_at":"2016-02-17T01:02:05Z","updated_at":"2016-02-17T01:02:05Z","body":"The following is our [ridiculous?] conclusion (altered slightly to anonymize and generalize).  Basically, we define reasonable default values at the root of the project for all API resource/method combinations and then override them with the correct specific values at the level of the actual function that is being defined.  Commentary at end.\r\n\r\nWarning: I am still mid-migration from legacy versions of SLS so this may or may not function as expected.  I assume @staceymoore 's code is working nicely at it would seem to and trying to use the same pattern of recursive template inclusion.\r\n\r\nAt the s-project.json level:\r\n```\r\n{\r\n  \"functionTemplate\": {\r\n    \"name\": \"$${functionName}\",\r\n    \"customName\": \"$${functionNameTemplate}\",\r\n    \"customRole\": \"$${roleNameTemplate}\",\r\n    \"handler\": \"$${handlerTemplate}\",\r\n    \"timeout\": \"$${timeout}\",\r\n    \"memorySize\": \"$${memorySize}\",\r\n    \"custom\": \"$${customTemplate}\",\r\n    \"endpoints\": \"$${endpointsTemplate}\",\r\n    \"events\": \"$${eventsTemplate}\"\r\n  },\r\n\r\n  \"functionName\": \"[OVERRIDE_ME_OR_ERROR]\",\r\n  \"functionNameTemplate\": \"${project}-${stage}-${name}\",\r\n  \"roleNameTemplate\": \"${project}-${stage}-${name}\",\r\n  \"handlerTemplate\": \"${name}/handler.handler\", // with multiple functions in s-function.json, would add \"handlerGetTemplate\", \"handlerPostTemplate\", et cetera\r\n  \"timeout\": 3,\r\n  \"memorySize\": 1024,\r\n  \"customTemplate\": {\r\n    \"excludePatterns\": [],\r\n    \"envVars\": [ \"SERVERLESS_STAGE\" ]\r\n  },\r\n  \"endpointsTemplate\": [],\r\n  \"eventsTemplate\": [],\r\n\r\n  \"endpointGetTemplate\": {\r\n    \"path\": \"$${pathTemplate}\",\r\n    \"method\": \"GET\",\r\n    \"type\": \"$${typeTemplate}\",\r\n    \"authorizationType\": \"$${authorizationTypeTemplate}\",\r\n    \"apiKeyRequired\": \"$${apiKeyRequiredTemplate},\r\n    \"requestParameters\": \"$${requestParametersTemplate}\",\r\n    \"requestTemplates\": \"$${requestTemplatesTemplate}\",\r\n    \"responses\": \"$${responsesGetTemplate}\"\r\n  },\r\n  \"endpointPatchTemplate\": {\r\n    \"path\": \"$${pathTemplate}\",\r\n    \"method\": \"PATCH\",\r\n    \"type\": \"$${typeTemplate}\",\r\n    \"authorizationType\": \"$${authorizationTypeTemplate}\",\r\n    \"apiKeyRequired\": \"$${apiKeyRequiredTemplate}\",\r\n    \"requestParameters\": \"$${requestParametersTemplate}\",\r\n    \"requestTemplates\": \"$${requestTemplatesTemplate}\",\r\n    \"responses\": \"$${responsesPatchTemplate}\"\r\n  },\r\n  \"endpointPostTemplate\": {\r\n    \"path\": \"$${pathTemplate}\",\r\n    \"method\": \"POST\",\r\n    \"type\": \"$${typeTemplate}\",\r\n    \"authorizationType\": \"$${authorizationTypeTemplate}\",\r\n    \"apiKeyRequired\": \"$${apiKeyRequiredTemplate}\",\r\n    \"requestParameters\": \"$${requestParametersTemplate}\",\r\n    \"requestTemplates\": \"$${requestTemplatesTemplate}\",\r\n    \"responses\": \"$${responsesPostTemplate}\"\r\n  },\r\n  \r\n  \"pathTemplate\": \"${component}/{id}/${name}\",\r\n  \"typeTemplate\": \"AWS\",\r\n  \"authorizationTypeTemplate\": \"AWS_IAM\",\r\n  \"requestParametersTemplate\": {},\r\n  \"requestTemplatesTemplate\": { \"application/json\": \"\" },\r\n\r\n  \"responsesGetTemplate\": {\r\n    \"default\": \"$${response200}\",\r\n    \"400:.*\":  \"$${response400}\",\r\n    \"403:.*\":  \"$${response403}\",\r\n    \"404:.*\":  \"$${response404}\",\r\n    \"422:.*\":  \"$${response422}\",\r\n    \"500:.*\":  \"$${response500}\",\r\n    \"504:.*\":  \"$${response504}\"\r\n  },\r\n  \"responsesPatchTemplate\": {\r\n    \"default\": \"$${response204}\",\r\n    \"400:.*\":  \"$${response400}\",\r\n    \"403:.*\":  \"$${response403}\",\r\n    \"404:.*\":  \"$${response404}\",\r\n    \"409:.*\":  \"$${response409}\",\r\n    \"412:.*\":  \"$${response412}\",\r\n    \"422:.*\":  \"$${response422}\",\r\n    \"500:.*\":  \"$${response500}\",\r\n    \"504:.*\":  \"$${response504}\"\r\n  },\r\n  \"responsesPostTemplate\": {\r\n    \"default\": \"$${response201}\",\r\n    \"400:.*\":  \"$${response400}\",\r\n    \"403:.*\":  \"$${response403}\",\r\n    \"422:.*\":  \"$${response422}\",\r\n    \"500:.*\":  \"$${response500}\",\r\n    \"504:.*\":  \"$${response504}\"\r\n  },\r\n\r\n  \"response200\": {\r\n    \"statusCode\": \"200\",\r\n    \"responseParameters\": \"$${responseParameters}\",\r\n    \"responseTemplates\": \"$${responseTemplates}\",\r\n    \"responseModels\": \"$${responseModels}\"\r\n  },\r\n  \"response201\": {\r\n    \"statusCode\": \"201\",\r\n    \"responseParameters\": \"$${responseParameters}\",\r\n    \"responseTemplates\": \"$${responseTemplates}\",\r\n    \"responseModels\": \"$${responseModels}\"\r\n  },\r\n  \"response204\": {\r\n    \"statusCode\": \"204\",\r\n    \"responseParameters\": \"$${responseParameters}\",\r\n    \"responseTemplates\": \"$${responseTemplates}\",\r\n    \"responseModels\": \"$${responseModels}\"\r\n  },\r\n  \"response400\": {\r\n    \"statusCode\": \"400\",\r\n    \"responseParameters\": \"$${responseParameters}\",\r\n    \"responseTemplates\": \"$${responseTemplates}\",\r\n    \"responseModels\": \"$${responseModels}\"\r\n  },\r\n  \"response403\": {\r\n    \"statusCode\": \"403\",\r\n    \"responseParameters\": \"$${responseParameters}\",\r\n    \"responseTemplates\": \"$${responseTemplates}\",\r\n    \"responseModels\": \"$${responseModels}\"\r\n  },\r\n  \"response404\": {\r\n    \"statusCode\": \"404\",\r\n    \"responseParameters\": \"$${responseParameters}\",\r\n    \"responseTemplates\": \"$${responseTemplates}\",\r\n    \"responseModels\": \"$${responseModels}\"\r\n  },\r\n  \"response409\": {\r\n    \"statusCode\": \"409\",\r\n    \"responseParameters\": \"$${responseParameters}\",\r\n    \"responseTemplates\": \"$${responseTemplates}\",\r\n    \"responseModels\": \"$${responseModels}\"\r\n  },\r\n  \"response412\": {\r\n    \"statusCode\": \"412\",\r\n    \"responseParameters\": \"$${responseParameters}\",\r\n    \"responseTemplates\": \"$${responseTemplates}\",\r\n    \"responseModels\": \"$${responseModels}\"\r\n  },\r\n  \"response422\": {\r\n    \"statusCode\": \"422\",\r\n    \"responseParameters\": \"$${responseParameters}\",\r\n    \"responseTemplates\": \"$${responseTemplates}\",\r\n    \"responseModels\": \"$${responseModels}\"\r\n  },\r\n  \"response500\": {\r\n    \"statusCode\": \"500\",\r\n    \"responseParameters\": \"$${responseParameters}\",\r\n    \"responseTemplates\": \"$${responseTemplates}\",\r\n    \"responseModels\": \"$${responseModels}\"\r\n  },\r\n  \"response504\": {\r\n    \"statusCode\": \"504\",\r\n    \"responseParameters\": \"$${responseParameters}\",\r\n    \"responseTemplates\": \"$${responseTemplates}\",\r\n    \"responseModels\": \"$${responseModels}\"\r\n  },\r\n\r\n  \"responseParameters\": {\r\n    \"method.response.header.Access-Control-Allow-Origin\": \"'*'\"\r\n  },\r\n  \"responseTemplates\": { \"application/json\": \"\" },\r\n  \"responseModels\": {}\r\n}\r\n```\r\n\r\nAt the s-function.json level:\r\n```\r\n{\r\n  \"functionName\": \"[NAME]\",\r\n  \"endpointsTemplate\": [\r\n    \"$${endpointsGetTemplate}\", // handles both get and post - would really like multiple endpoint declarations per s-function.json to truly unleash this\r\n    \"$${endpointsPostTemplate}\"\r\n  ],\r\n  \"requestParametersTemplate\": {\r\n    [...]\r\n  },\r\n  \"requestTemplatesTemplate\": {\r\n    \"application/json\": {\r\n      [...]\r\n  }\r\n}\r\n```\r\n\r\nThe entirety of s-function now looks like so:\r\n```\r\n\"$${functionTemplate}\"\r\n```\r\n\r\n(particularly @ac360) It seems wrong for s-function.json to end up so content-free because I want my API to abide by relative standards and require minimum verbosity and restatement.  This is why I've been going on about ideas of an inheritance and overriding scheme.  I think there's good room for doing away with all s-template.json files and using the s-[project/component/function].json files in a similar inheritance and override like fashion.  A configuration stack and merge mechanism would become necessary but it shouldn't be too rough to reasonably generally and clearly define those."}}