{"action":"created","comment":{"url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/pulls/comments/70235200","id":70235200,"diff_hunk":"@@ -1,21 +1,53 @@\n-from transform import app\n-\n-from flask import request, make_response, send_file\n-from jinja2 import Environment, PackageLoader\n+from transform import app, env\n+from settings import logger\n+from flask import request, make_response, jsonify\n import dateutil.parser\n-import json\n \n \n-env = Environment(loader=PackageLoader('transform', 'templates'))\n+@app.errorhandler(400)\n+def errorhandler_400(e):\n+    return client_error(repr(e))\n+\n+\n+def client_error(error=None):\n+    logger.error(error, request=request.data.decode('UTF8'))\n+    message = {\n+        'status': 400,\n+        'message': error,\n+        'uri': request.url\n+    }\n+    resp = jsonify(message)\n+    resp.status_code = 400\n+\n+    return resp\n+\n+\n+@app.errorhandler(500)\n+def server_error(e):\n+    logger.error(\"Server Error\", exception=repr(e), request=request.data.decode('UTF8'))\n+    message = {\n+        'status': 500,\n+        'message': \"Internal server error: \" + repr(e)\n+    }\n+    resp = jsonify(message)\n+    resp.status_code = 500\n+\n+    return resp\n \n \n @app.route('/xml', methods=['POST'])\n def render_xml():\n     response = request.get_json(force=True)\n-    template = env.get_template('xml.tmpl')\n+    if not response:\n+        client_error(\"Request payload was empty\")\n+\n+    # TODO: what happens if response doesn't have submitted_at or it can't be parsed?\n     submitted_date = dateutil.parser.parse(response['submitted_at'])","path":"transform/views/main.py","position":52,"original_position":52,"commit_id":"03da77c7e0ed809392498e233e7b7611c0cc70c1","original_commit_id":"03da77c7e0ed809392498e233e7b7611c0cc70c1","user":{"login":"ajmaddaford","id":1754822,"avatar_url":"https://avatars.githubusercontent.com/u/1754822?v=3","gravatar_id":"","url":"https://api.github.com/users/ajmaddaford","html_url":"https://github.com/ajmaddaford","followers_url":"https://api.github.com/users/ajmaddaford/followers","following_url":"https://api.github.com/users/ajmaddaford/following{/other_user}","gists_url":"https://api.github.com/users/ajmaddaford/gists{/gist_id}","starred_url":"https://api.github.com/users/ajmaddaford/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ajmaddaford/subscriptions","organizations_url":"https://api.github.com/users/ajmaddaford/orgs","repos_url":"https://api.github.com/users/ajmaddaford/repos","events_url":"https://api.github.com/users/ajmaddaford/events{/privacy}","received_events_url":"https://api.github.com/users/ajmaddaford/received_events","type":"User","site_admin":false},"body":"Catch and throw client error - these are invalid requests from the client","created_at":"2016-07-11T10:34:53Z","updated_at":"2016-07-11T10:34:53Z","html_url":"https://github.com/ONSdigital/sdx-transform-testform/pull/1#discussion_r70235200","pull_request_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/pulls/1","_links":{"self":{"href":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/pulls/comments/70235200"},"html":{"href":"https://github.com/ONSdigital/sdx-transform-testform/pull/1#discussion_r70235200"},"pull_request":{"href":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/pulls/1","id":76735611,"html_url":"https://github.com/ONSdigital/sdx-transform-testform/pull/1","diff_url":"https://github.com/ONSdigital/sdx-transform-testform/pull/1.diff","patch_url":"https://github.com/ONSdigital/sdx-transform-testform/pull/1.patch","issue_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/issues/1","number":1,"state":"open","locked":false,"title":"Standards changes","user":{"login":"elliott-jenkins","id":13519859,"avatar_url":"https://avatars.githubusercontent.com/u/13519859?v=3","gravatar_id":"","url":"https://api.github.com/users/elliott-jenkins","html_url":"https://github.com/elliott-jenkins","followers_url":"https://api.github.com/users/elliott-jenkins/followers","following_url":"https://api.github.com/users/elliott-jenkins/following{/other_user}","gists_url":"https://api.github.com/users/elliott-jenkins/gists{/gist_id}","starred_url":"https://api.github.com/users/elliott-jenkins/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elliott-jenkins/subscriptions","organizations_url":"https://api.github.com/users/elliott-jenkins/orgs","repos_url":"https://api.github.com/users/elliott-jenkins/repos","events_url":"https://api.github.com/users/elliott-jenkins/events{/privacy}","received_events_url":"https://api.github.com/users/elliott-jenkins/received_events","type":"User","site_admin":false},"body":"**Changes**\r\n\r\nflake8, travis, README and structlog\r\n\r\n**How to test**\r\n\r\nRead README, check Travis is passing\r\n\r\n**Who can test**\r\n\r\nAnyone but @elliott-jenkins","created_at":"2016-07-08T10:58:04Z","updated_at":"2016-07-11T10:34:53Z","closed_at":null,"merged_at":null,"merge_commit_sha":"cd0176b2c0760cee44f7a185bcaeb14c42268b63","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/pulls/1/commits","review_comments_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/pulls/1/comments","review_comment_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/issues/1/comments","statuses_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/statuses/03da77c7e0ed809392498e233e7b7611c0cc70c1","head":{"label":"ONSdigital:standards-changes","ref":"standards-changes","sha":"03da77c7e0ed809392498e233e7b7611c0cc70c1","user":{"login":"ONSdigital","id":6865137,"avatar_url":"https://avatars.githubusercontent.com/u/6865137?v=3","gravatar_id":"","url":"https://api.github.com/users/ONSdigital","html_url":"https://github.com/ONSdigital","followers_url":"https://api.github.com/users/ONSdigital/followers","following_url":"https://api.github.com/users/ONSdigital/following{/other_user}","gists_url":"https://api.github.com/users/ONSdigital/gists{/gist_id}","starred_url":"https://api.github.com/users/ONSdigital/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ONSdigital/subscriptions","organizations_url":"https://api.github.com/users/ONSdigital/orgs","repos_url":"https://api.github.com/users/ONSdigital/repos","events_url":"https://api.github.com/users/ONSdigital/events{/privacy}","received_events_url":"https://api.github.com/users/ONSdigital/received_events","type":"Organization","site_admin":false},"repo":{"id":62555284,"name":"sdx-transform-testform","full_name":"ONSdigital/sdx-transform-testform","owner":{"login":"ONSdigital","id":6865137,"avatar_url":"https://avatars.githubusercontent.com/u/6865137?v=3","gravatar_id":"","url":"https://api.github.com/users/ONSdigital","html_url":"https://github.com/ONSdigital","followers_url":"https://api.github.com/users/ONSdigital/followers","following_url":"https://api.github.com/users/ONSdigital/following{/other_user}","gists_url":"https://api.github.com/users/ONSdigital/gists{/gist_id}","starred_url":"https://api.github.com/users/ONSdigital/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ONSdigital/subscriptions","organizations_url":"https://api.github.com/users/ONSdigital/orgs","repos_url":"https://api.github.com/users/ONSdigital/repos","events_url":"https://api.github.com/users/ONSdigital/events{/privacy}","received_events_url":"https://api.github.com/users/ONSdigital/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ONSdigital/sdx-transform-testform","description":null,"fork":false,"url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform","forks_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/forks","keys_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/teams","hooks_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/hooks","issue_events_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/issues/events{/number}","events_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/events","assignees_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/assignees{/user}","branches_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/branches{/branch}","tags_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/tags","blobs_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/git/refs{/sha}","trees_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/statuses/{sha}","languages_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/languages","stargazers_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/stargazers","contributors_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/contributors","subscribers_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/subscribers","subscription_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/subscription","commits_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/commits{/sha}","git_commits_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/git/commits{/sha}","comments_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/comments{/number}","issue_comment_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/issues/comments{/number}","contents_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/contents/{+path}","compare_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/merges","archive_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/downloads","issues_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/issues{/number}","pulls_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/pulls{/number}","milestones_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/milestones{/number}","notifications_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/labels{/name}","releases_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/releases{/id}","deployments_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/deployments","created_at":"2016-07-04T10:54:50Z","updated_at":"2016-07-04T13:53:12Z","pushed_at":"2016-07-08T10:58:04Z","git_url":"git://github.com/ONSdigital/sdx-transform-testform.git","ssh_url":"git@github.com:ONSdigital/sdx-transform-testform.git","clone_url":"https://github.com/ONSdigital/sdx-transform-testform.git","svn_url":"https://github.com/ONSdigital/sdx-transform-testform","homepage":null,"size":21,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"ONSdigital:master","ref":"master","sha":"fb840e774317fc46e151e759ee36bf31068d23a0","user":{"login":"ONSdigital","id":6865137,"avatar_url":"https://avatars.githubusercontent.com/u/6865137?v=3","gravatar_id":"","url":"https://api.github.com/users/ONSdigital","html_url":"https://github.com/ONSdigital","followers_url":"https://api.github.com/users/ONSdigital/followers","following_url":"https://api.github.com/users/ONSdigital/following{/other_user}","gists_url":"https://api.github.com/users/ONSdigital/gists{/gist_id}","starred_url":"https://api.github.com/users/ONSdigital/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ONSdigital/subscriptions","organizations_url":"https://api.github.com/users/ONSdigital/orgs","repos_url":"https://api.github.com/users/ONSdigital/repos","events_url":"https://api.github.com/users/ONSdigital/events{/privacy}","received_events_url":"https://api.github.com/users/ONSdigital/received_events","type":"Organization","site_admin":false},"repo":{"id":62555284,"name":"sdx-transform-testform","full_name":"ONSdigital/sdx-transform-testform","owner":{"login":"ONSdigital","id":6865137,"avatar_url":"https://avatars.githubusercontent.com/u/6865137?v=3","gravatar_id":"","url":"https://api.github.com/users/ONSdigital","html_url":"https://github.com/ONSdigital","followers_url":"https://api.github.com/users/ONSdigital/followers","following_url":"https://api.github.com/users/ONSdigital/following{/other_user}","gists_url":"https://api.github.com/users/ONSdigital/gists{/gist_id}","starred_url":"https://api.github.com/users/ONSdigital/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ONSdigital/subscriptions","organizations_url":"https://api.github.com/users/ONSdigital/orgs","repos_url":"https://api.github.com/users/ONSdigital/repos","events_url":"https://api.github.com/users/ONSdigital/events{/privacy}","received_events_url":"https://api.github.com/users/ONSdigital/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ONSdigital/sdx-transform-testform","description":null,"fork":false,"url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform","forks_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/forks","keys_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/teams","hooks_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/hooks","issue_events_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/issues/events{/number}","events_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/events","assignees_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/assignees{/user}","branches_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/branches{/branch}","tags_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/tags","blobs_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/git/refs{/sha}","trees_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/statuses/{sha}","languages_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/languages","stargazers_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/stargazers","contributors_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/contributors","subscribers_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/subscribers","subscription_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/subscription","commits_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/commits{/sha}","git_commits_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/git/commits{/sha}","comments_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/comments{/number}","issue_comment_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/issues/comments{/number}","contents_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/contents/{+path}","compare_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/merges","archive_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/downloads","issues_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/issues{/number}","pulls_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/pulls{/number}","milestones_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/milestones{/number}","notifications_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/labels{/name}","releases_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/releases{/id}","deployments_url":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/deployments","created_at":"2016-07-04T10:54:50Z","updated_at":"2016-07-04T13:53:12Z","pushed_at":"2016-07-08T10:58:04Z","git_url":"git://github.com/ONSdigital/sdx-transform-testform.git","ssh_url":"git@github.com:ONSdigital/sdx-transform-testform.git","clone_url":"https://github.com/ONSdigital/sdx-transform-testform.git","svn_url":"https://github.com/ONSdigital/sdx-transform-testform","homepage":null,"size":21,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/pulls/1"},"html":{"href":"https://github.com/ONSdigital/sdx-transform-testform/pull/1"},"issue":{"href":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/issues/1"},"comments":{"href":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/ONSdigital/sdx-transform-testform/statuses/03da77c7e0ed809392498e233e7b7611c0cc70c1"}}}}
{"actor":{"display_login":"ajmaddaford"}}