Skip to content

Commit

Permalink
handle errors
Browse files Browse the repository at this point in the history
  • Loading branch information
aenima-x committed Jun 6, 2021
1 parent 596b1d1 commit 7e81b9a
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions src/app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python

from flask import Flask, Response, request
from flask import Flask, Response, request, abort

app = Flask(__name__)

Expand All @@ -16,25 +16,32 @@


def get_response(action):
file_path = responses_files.get(action)
print(f'File: {file_path} for action: {action}')
with open(file_path) as f:
data = f.read()
return data
file_path = responses_files.get(action, None)
if file_path:
print(f'File: {file_path} for action: {action}')
with open(file_path) as f:
data = f.read()
return data
else:
return None


@app.route("/TonePrintService.svc", methods=['POST'])
def fake_service():
print("--------------------------------")
print("Headers: ", request.headers)
response = Response()
action = request.headers['Soapaction'].split('/')[-1].replace('"', '')
print("Action:", action)

response_text = get_response(action)
response.data = response_text
return response

action = request.headers.get('Soapaction', '').split('/')[-1].replace('"', '')
if action:
print("Action:", action)
response_text = get_response(action)
if response_text:
response.data = response_text
return response
else:
abort(404, 'Unknown action')
else:
abort(400, 'Missing action')

if __name__ == "__main__":
app.run(debug=True, port=443, ssl_context=('ssl/cert.pem', 'ssl/key.pem'))

0 comments on commit 7e81b9a

Please sign in to comment.