From 7dcb664f35e1e5a36d85a12f8ceb23df736b86bc Mon Sep 17 00:00:00 2001
From: Sebastian Steiner <e1029038@student.tuwien.ac.at>
Date: Tue, 11 Dec 2018 14:17:28 +0100
Subject: [PATCH] fixed issue of internal server error if single json object
 not posted as list, refined server response for GET

---
 service-analysis/sentiment_analysis.py | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/service-analysis/sentiment_analysis.py b/service-analysis/sentiment_analysis.py
index 4e8f63e..7b449d2 100644
--- a/service-analysis/sentiment_analysis.py
+++ b/service-analysis/sentiment_analysis.py
@@ -10,15 +10,15 @@ api = Api(app)
 
 indicoio.config.api_key = '525f16078717a430f9dac17cdc9dbaa3'
 
-input_error_409 = 'Input must be a JSON string. JSON objects must contain contain key text.'
+input_error_409 = 'Input must be a list of JSON objects. JSON objects must contain contain key text.'
 service_error_503 = 'The sentiment analysis service is currently unavailable.'
 
 class Sentiment_Analysis(Resource):
 	def get(self):
-		return "POST a JSON string as content-type: application/json. JSON objects must contain key 'text'."
+		return "POST a list of JSON objects as content-type: application/json. JSON objects must contain key 'text'.", 405, {'Allow': 'GET'}
 		
 	def post(self):
-		if not request.json:
+		if not request.json or not isinstance(request.json, (list,)):
 			return abort(409, message=input_error_409)
 		texts = request.json
 		text_array = []
@@ -35,6 +35,10 @@ class Sentiment_Analysis(Resource):
 		sentiment = value/len(text_array)
 		data = {'sentiment': sentiment}
 		return data, 200, {'Content-Type': 'application/json'}
+		#r = Response(response=json.dumps(data), status=200, mimetype="application/json")
+		#r.headers["Content-Type"] = "application/json"
+		#return r
+		#return output_json(json.dumps(data), 200, headers={'Content-Type': "application/json"})
 				
 api.add_resource(Sentiment_Analysis, '/')
 
-- 
2.43.0