Skip to content

Commit

Permalink
Merge pull request #9 from endbro/master
Browse files Browse the repository at this point in the history
Return http 500 err when parsing xml fails
  • Loading branch information
Jonas Als Christensen authored Apr 27, 2022
2 parents 95053d8 + 225ce90 commit de3286d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3-alpine
FROM python:3.9-alpine3.15
LABEL author="Endre Brønnum"
LABEL author.email="endre.bronnum@sesam.io"

Expand Down
4 changes: 2 additions & 2 deletions service/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
xmltodict==0.12.0
requests==2.10.0
Flask==2.0.1
requests==2.27.1
Flask==2.1.1
PyYAML==5.1
10 changes: 6 additions & 4 deletions service/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import yaml

from xml.parsers.expat import ExpatError
from flask import Flask, request, Response, jsonify
from flask import Flask, abort, request, Response, jsonify
import os
import requests

Expand Down Expand Up @@ -140,7 +140,7 @@ def xml_string_to_json():
- xml attributes will be prefixed by "@" in the json data
- accepts entities with non-existing XML string
"""

if(not request.is_json):
return "Request body was not JSON", 400

Expand All @@ -159,7 +159,8 @@ def emit_entities():
# Sesam packs entities in an array before firing off a request and expects an array back. 
yield '['
first = True
for item in request_payload:
for item in request_payload:
currentItem = item["_id"]
if not first:
yield ','
else:
Expand Down Expand Up @@ -189,7 +190,8 @@ def emit_entities():
yield ']'

except Exception as ex:
logger.error(f"Exiting with error: {ex}")
logger.error(f"Exiting with error: {ex} - suspected entity = {currentItem}")
abort(500)

return Response(response=emit_entities(), mimetype='application/json')

Expand Down

0 comments on commit de3286d

Please sign in to comment.