diff --git a/request-management-api/request_api/resources/foiadmin.py b/request-management-api/request_api/resources/foiadmin.py index 864157ec4..218fd9156 100644 --- a/request-management-api/request_api/resources/foiadmin.py +++ b/request-management-api/request_api/resources/foiadmin.py @@ -30,6 +30,7 @@ API = Namespace('FOIAdmin', description='Endpoints for FOI admin management') TRACER = Tracer.get_instance() +CUSTOM_KEYERROR_MESSAGE = "Key error has occured: " """Custom exception messages """ @@ -50,9 +51,9 @@ def get(): try: result = programareadivisionservice().getallprogramareadivisions() return json.dumps(result), 200 - except KeyError as err: - return {'status': False, 'message':err.messages}, 400 - except BusinessException as exception: + except KeyError as error: + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 + except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @cors_preflight('POST,OPTIONS') @@ -73,8 +74,8 @@ def post(): # if result.success == True: # asyncio.ensure_future(); return {'status': result.success, 'message':result.message, 'id':result.identifier}, 200 - except KeyError as err: - return {'status': False, 'message':err.messages}, 400 + except KeyError as error: + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -97,8 +98,8 @@ def put(divisionid): # if result.success == True: # asyncio.ensure_future(); return {'status': result.success, 'message':result.message, 'id':result.identifier}, 200 - except KeyError as err: - return {'status': False, 'message':err.messages}, 400 + except KeyError as error: + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -118,8 +119,8 @@ def put(divisionid): # if result.success == True: # asyncio.ensure_future(); return {'status': result.success, 'message':result.message, 'id':result.identifier}, 200 - except KeyError as err: - return {'status': False, 'message':err.messages}, 400 + except KeyError as error: + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 diff --git a/request-management-api/request_api/resources/foicfrfee.py b/request-management-api/request_api/resources/foicfrfee.py index e8dad2f91..44877f076 100644 --- a/request-management-api/request_api/resources/foicfrfee.py +++ b/request-management-api/request_api/resources/foicfrfee.py @@ -36,6 +36,7 @@ """Custom exception messages """ EXCEPTION_MESSAGE_BAD_REQUEST='Bad Request' +CUSTOM_KEYERROR_MESSAGE = "Key error has occured: " @cors_preflight('POST,OPTIONS') @API.route('/foicfrfee/foirequest//ministryrequest/') @@ -57,10 +58,10 @@ def post(requestid, ministryrequestid): return {'status': result.success, 'message':result.message,'id':result.identifier} , 200 except ValidationError as verr: logging.error(verr) - return {'status': False, 'message':verr.messages}, 400 - except KeyError as err: - logging.error(err) - return {'status': False, 'message': EXCEPTION_MESSAGE_BAD_REQUEST}, 400 + return {'status': False, 'message': str(verr)}, 400 + except KeyError as error: + logging.error(CUSTOM_KEYERROR_MESSAGE + str(error)) + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -87,10 +88,10 @@ def post(requestid, ministryrequestid): return {'status': result.success, 'message':result.message,'id':result.identifier} , 200 except ValidationError as verr: logging.error(verr) - return {'status': False, 'message':verr.messages}, 400 - except KeyError as err: - logging.error(err) - return {'status': False, 'message': EXCEPTION_MESSAGE_BAD_REQUEST}, 400 + return {'status': False, 'message': str(verr)}, 400 + except KeyError as error: + logging.error(CUSTOM_KEYERROR_MESSAGE + str(error)) + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -109,7 +110,7 @@ def get(requestid): try: result = {"current": cfrfeeservice().getcfrfee(requestid), "history": cfrfeeservice().getcfrfeehistory(requestid)} return json.dumps(result), 200 - except KeyError as err: - return {'status': False, 'message':err.messages}, 400 + except KeyError as error: + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 diff --git a/request-management-api/request_api/resources/foicomment.py b/request-management-api/request_api/resources/foicomment.py index f68db9c50..4f88917ba 100644 --- a/request-management-api/request_api/resources/foicomment.py +++ b/request-management-api/request_api/resources/foicomment.py @@ -35,6 +35,7 @@ """Custom exception messages """ EXCEPTION_MESSAGE_BAD_REQUEST='Bad Request' +CUSTOM_KEYERROR_MESSAGE = "Key error has occured: " @cors_preflight('POST,OPTIONS') @API.route('/foicomment/ministryrequest') @@ -54,8 +55,8 @@ def post(): if result.success == True: asyncio.ensure_future(eventservice().postcommentevent(result.identifier, "ministryrequest", AuthHelper.getuserid())) return {'status': result.success, 'message':result.message,'id':result.identifier} , 200 - except KeyError as err: - return {'status': False, 'message':err.messages}, 400 + except KeyError as error: + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -77,8 +78,8 @@ def post(): if result.success == True: asyncio.ensure_future(eventservice().postcommentevent(result.identifier, "rawrequest", AuthHelper.getuserid())) return {'status': result.success, 'message':result.message,'id':result.identifier} , 200 - except KeyError as err: - return {'status': False, 'message':err.messages}, 400 + except KeyError as error: + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -108,8 +109,8 @@ def get(requesttype, requestid): return json.dumps(result), 200 else: return {'status': 401, 'message':'Restricted Request'} , 401 - except KeyError as err: - return {'status': False, 'message':err.messages}, 400 + except KeyError as error: + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -136,8 +137,8 @@ def put(requesttype, commentid): if result.success == True: asyncio.ensure_future(eventservice().postcommentevent(result.identifier, requesttype, AuthHelper.getuserid(), True)) return {'status': result.success, 'message':result.message,'id':result.identifier} , 200 - except KeyError as err: - return {'status': False, 'message':err.messages}, 400 + except KeyError as error: + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -166,8 +167,8 @@ def put(requesttype, commentid): if result.success == True: asyncio.ensure_future(eventservice().postcommentevent(commentid, requesttype, AuthHelper.getuserid(), existingtaggedusers=result.args[0])) return {'status': result.success, 'message':result.message,'id':result.identifier} , 200 - except KeyError as err: - return {'status': False, 'message':err.messages}, 400 + except KeyError as error: + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -184,7 +185,7 @@ def get(requestid=None): result = commentservice().createcommenttagginguserlist("rawrequest",requestid) return json.dumps(result), 200 except ValueError: - return {'status': 500, 'message':"Invalid Request"}, 400 + return {'status': 500, 'message':"Invalid Request"}, 500 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -200,6 +201,6 @@ def get(ministryrequestid=None): result = commentservice().createcommenttagginguserlist("ministryrequest",ministryrequestid) return json.dumps(result), 200 except ValueError: - return {'status': 500, 'message':"Invalid Request"}, 400 + return {'status': 500, 'message':"Invalid Request"}, 500 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 \ No newline at end of file diff --git a/request-management-api/request_api/resources/foidocument.py b/request-management-api/request_api/resources/foidocument.py index f095f9444..b661c394f 100644 --- a/request-management-api/request_api/resources/foidocument.py +++ b/request-management-api/request_api/resources/foidocument.py @@ -30,7 +30,8 @@ API = Namespace('FOIDocument', description='Endpoints for FOI Document management') -TRACER = Tracer.get_instance() +TRACER = Tracer.get_instance() +CUSTOM_KEYERROR_MESSAGE = "Key error has occured: " @cors_preflight('GET,OPTIONS') @@ -49,8 +50,8 @@ def get(requestid, requesttype): try: result = documentservice().getrequestdocumentsbyrole(requestid, requesttype, AuthHelper.isministrymember()) return json.dumps(result), 200 - except KeyError as err: - return {'status': False, 'message':err.messages}, 400 + except KeyError as error: + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -73,9 +74,9 @@ def post(requestid, requesttype): result = documentservice().createrequestdocument(requestid, documentschema, AuthHelper.getuserid(), requesttype) return {'status': result.success, 'message':result.message} , 200 except ValidationError as err: - return {'status': False, 'message':err.messages}, 400 - except KeyError as err: - return {'status': False, 'message':err.messages}, 400 + return {'status': False, 'message': str(err)}, 400 + except KeyError as error: + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -97,12 +98,50 @@ def post(requestid, documentid, requesttype): result = documentservice().createrequestdocumentversion(requestid, documentid, documentschema, AuthHelper.getuserid(), requesttype) return {'status': result.success, 'message':result.message,'id':result.identifier} , 200 except ValidationError as err: - return {'status': False, 'message':err.messages}, 400 - except KeyError as err: - return {'status': False, 'message':err.messages}, 400 + return {'status': False, 'message': str(err)}, 400 + except KeyError as error: + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 +@cors_preflight('POST,OPTIONS') +@API.route('/foidocument///documentid//reclassify') +class ReclassifyFOIDocument(Resource): + """Resource for reclassifying uploaded attachments of FOI requests.""" + + @staticmethod + @TRACER.trace() + @cross_origin(origins=allowedorigins()) + @auth.require + def post(requesttype, requestid, documentid): + try: + requestjson = request.get_json() + documentschema = ReclassifyDocumentSchema().load(requestjson) + activedocuments = documentservice().getactiverequestdocuments(requestid, requesttype) + documentpath = 'no documentpath found' + if (requesttype == 'ministryrequest'): + for document in activedocuments: + if document['foiministrydocumentid'] == int(documentid): + documentpath = document['documentpath'] + else: + for document in activedocuments: + if document['foidocumentid'] == int(documentid): + documentpath = document['documentpath'] + + # move document in S3 + moveresult = documentservice().copyrequestdocumenttonewlocation(documentschema['category'], documentpath) + # save new version of document with updated documentpath + if moveresult['status'] == 'success': + result = documentservice().createrequestdocumentversion(requestid, documentid, documentschema, AuthHelper.getuserid(), requesttype) + return {'status': result.success, 'message':result.message,'id':result.identifier} , 200 + return {'status': False, 'message': "Something went wrong moving the document's location" }, 500 + except ValidationError as err: + return {'status': False, 'message': str(err)}, 400 + except KeyError as error: + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 + except BusinessException as exception: + return {'status': exception.status_code, 'message':exception.message}, 500 + @cors_preflight('POST,OPTIONS') @API.route('/foidocument///documentid//replace') class ReplaceFOIDocument(Resource): @@ -120,9 +159,9 @@ def post(requestid, documentid, requesttype): result = documentservice().createrequestdocumentversion(requestid, documentid, documentschema, AuthHelper.getuserid(), requesttype) return {'status': result.success, 'message':result.message,'id':result.identifier} , 200 except ValidationError as err: - return {'status': False, 'message':err.messages}, 400 - except KeyError as err: - return {'status': False, 'message':err.messages}, 400 + return {'status': False, 'message': str(err)}, 400 + except KeyError as error: + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -141,7 +180,7 @@ def post(requestid, documentid, requesttype): try: result = documentservice().deleterequestdocument(requestid, documentid, AuthHelper.getuserid(), requesttype) return {'status': result.success, 'message':result.message,'id':result.identifier} , 200 - except KeyError as err: - return {'status': False, 'message':err.messages}, 400 + except KeyError as error: + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 \ No newline at end of file diff --git a/request-management-api/request_api/resources/foiemail.py b/request-management-api/request_api/resources/foiemail.py index 0b2aa80b1..c175cc6f3 100644 --- a/request-management-api/request_api/resources/foiemail.py +++ b/request-management-api/request_api/resources/foiemail.py @@ -32,6 +32,7 @@ API = Namespace('FOIEmail', description='Endpoints for FOI EMAIL management') TRACER = Tracer.get_instance() +CUSTOM_KEYERROR_MESSAGE = "Key error has occured: " @cors_preflight('POST,OPTIONS') @API.route('/foiemail//ministryrequest//') @@ -50,9 +51,9 @@ def post(requestid, ministryrequestid, servicename): result = emailservice().send(servicename.upper(), requestid, ministryrequestid, emailschema) return json.dumps(result), 200 if result["success"] == True else 500 except ValueError as err: - return {'status': 500, 'message':err.messages}, 500 - except KeyError as err: - return {'status': False, 'message':err.messages}, 400 + return {'status': 500, 'message': str(err)}, 500 + except KeyError as error: + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -71,9 +72,9 @@ def post(requestid, ministryrequestid, servicename): result = emailservice().acknowledge(servicename.upper(), requestid, ministryrequestid) return json.dumps(result), 200 if result["success"] == True else 500 except ValueError as err: - return {'status': 500, 'message':err.messages}, 500 - except KeyError as err: - return {'status': False, 'message':err.messages}, 400 + return {'status': 500, 'message': str(err)}, 500 + except KeyError as error: + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 diff --git a/request-management-api/request_api/resources/foiextension.py b/request-management-api/request_api/resources/foiextension.py index 86c9ef0d6..ddb8280ac 100644 --- a/request-management-api/request_api/resources/foiextension.py +++ b/request-management-api/request_api/resources/foiextension.py @@ -37,6 +37,7 @@ """Custom exception messages """ EXCEPTION_MESSAGE_BAD_REQUEST='Bad Request' +CUSTOM_KEYERROR_MESSAGE = "Key error has occured: " @cors_preflight('GET,OPTIONS') @API.route('/foiextension/ministryrequest/') @@ -52,8 +53,8 @@ def get(requestid): try: extensionrecords = extensionservice().getrequestextensions(requestid) return json.dumps(extensionrecords), 200 - except KeyError as err: - return {'status': False, 'message':err.messages}, 400 + except KeyError as error: + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -71,8 +72,8 @@ def get(extensionid): try: extensionrecord = extensionservice().getrequestextension(extensionid) return json.dumps(extensionrecord), 200 - except KeyError as err: - return {'status': False, 'message':err.messages}, 400 + except KeyError as error: + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -96,8 +97,8 @@ def post(requestid, ministryrequestid): eventservice().posteventforextension(ministryrequestid, result.identifier, AuthHelper.getuserid(), AuthHelper.getusername(), "add") newduedate, = result.args return {'status': result.success, 'message':result.message,'id':result.identifier, 'newduedate': newduedate or None} , 200 - except KeyError as err: - return {'status': False, 'message':err.messages}, 400 + except KeyError as error: + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -121,8 +122,8 @@ def post(ministryrequestid): if len(result.args) > 0: eventservice().posteventforaxisextension(ministryrequestid, result.args[0], AuthHelper.getuserid(), AuthHelper.getusername(), "add") return {'status': result.success, 'message':result.message} , 200 - except KeyError as err: - return {'status': False, 'message':err.messages}, 400 + except KeyError as error: + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -145,8 +146,8 @@ def post(requestid, ministryrequestid, extensionid): # posteventforextension moved to createrequestextensionversion to generate the comments before updating the ministry table with new due date newduedate = result.args[-1] if len(result.args) > 0 else None return {'status': result.success, 'message':result.message,'id':result.identifier, 'newduedate': newduedate or None} , 200 - except KeyError as err: - return {'status': False, 'message':err.messages}, 400 + except KeyError as error: + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -167,7 +168,7 @@ def post(requestid, ministryrequestid, extensionid): eventservice().posteventforextension(ministryrequestid, extensionid, AuthHelper.getuserid(), AuthHelper.getusername(), "delete") newduedate = result.args[-1] if len(result.args) > 0 else None return {'status': result.success, 'message':result.message,'id':result.identifier, 'newduedate': newduedate or None} , 200 - except KeyError as err: - return {'status': False, 'message':err.messages}, 400 + except KeyError as error: + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 \ No newline at end of file diff --git a/request-management-api/request_api/resources/foinotification.py b/request-management-api/request_api/resources/foinotification.py index a95fef873..f5a3bf637 100644 --- a/request-management-api/request_api/resources/foinotification.py +++ b/request-management-api/request_api/resources/foinotification.py @@ -30,6 +30,7 @@ API = Namespace('FOINotification', description='Endpoints for FOI notification management') TRACER = Tracer.get_instance() +CUSTOM_KEYERROR_MESSAGE = "Key error has occured: " @cors_preflight('GET,OPTIONS') @API.route('/foinotifications') @@ -47,8 +48,8 @@ def get(): return json.dumps(result), 200 except ValueError: return {'status': 500, 'message':"Invalid Request Id"}, 500 - except KeyError as err: - return {'status': False, 'message':err.messages}, 400 + except KeyError as error: + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -72,8 +73,8 @@ def delete(type=None,idnumber=None,notficationid=None): return {'status': result.success, 'message':result.message,'id':result.identifier} , 500 except ValueError: return {'status': 500, 'message':"Invalid Request Id"}, 500 - except KeyError as err: - return {'status': False, 'message':err.messages}, 400 + except KeyError as error: + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -92,8 +93,8 @@ def post(): reminderresponse = eventservice().postreminderevent() respcode = 200 if reminderresponse.success == True else 500 return {'status': reminderresponse.success, 'message':reminderresponse.message,'id': reminderresponse.identifier} , respcode - except KeyError as err: - return {'status': False, 'message':err.messages}, 400 + except KeyError as error: + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -113,7 +114,7 @@ def post(request_id: int, ministry_request_id: int): reminderresponse = eventservice().postpaymentexpiryevent(ministry_request_id) respcode = 200 if reminderresponse.success == True else 500 return {'status': reminderresponse.success, 'message':reminderresponse.message,'id': reminderresponse.identifier} , respcode - except KeyError as err: - return {'status': False, 'message':err.messages}, 400 + except KeyError as error: + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 \ No newline at end of file diff --git a/request-management-api/request_api/resources/foipayment.py b/request-management-api/request_api/resources/foipayment.py index d5e7be7b5..b2670c6ff 100644 --- a/request-management-api/request_api/resources/foipayment.py +++ b/request-management-api/request_api/resources/foipayment.py @@ -31,6 +31,7 @@ API = Namespace('FOIPayment', description='Endpoints for FOI Payment management') TRACER = Tracer.get_instance() +CUSTOM_KEYERROR_MESSAGE = "Key error has occured: " @cors_preflight('POST,OPTIONS') @API.route('/foipayment//ministryrequest/') @@ -48,8 +49,8 @@ def post(requestid, ministryrequestid): paymentschema = FOIRequestPaymentSchema().load(requestjson) result = paymentservice().createpayment(requestid, ministryrequestid, paymentschema) return {'status': result.success, 'message':result.message,'id':result.identifier} , 200 - except KeyError as err: - return {'status': False, 'message':err.messages}, 400 + except KeyError as error: + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -69,8 +70,8 @@ def post(requestid, ministryrequestid): paymentschema = FOIRequestPaymentSchema().load(requestjson) result = paymentservice().cancelpayment(requestid, ministryrequestid, paymentschema) return {'status': result.success, 'message':result.message,'id':result.identifier} , 200 - except KeyError as err: - return {'status': False, 'message':err.messages}, 400 + except KeyError as error: + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -88,8 +89,8 @@ def get(requestid, ministryrequestid): try: result = paymentservice().getpayment(requestid, ministryrequestid) return json.dumps(result), 200 - except KeyError as err: - return {'status': False, 'message':err.messages}, 400 + except KeyError as error: + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 diff --git a/request-management-api/request_api/resources/foirecord.py b/request-management-api/request_api/resources/foirecord.py index e53181c80..71fa93b55 100644 --- a/request-management-api/request_api/resources/foirecord.py +++ b/request-management-api/request_api/resources/foirecord.py @@ -30,6 +30,7 @@ API = Namespace('FOIWatcher', description='Endpoints for FOI record management') TRACER = Tracer.get_instance() +CUSTOM_KEYERROR_MESSAGE = "Key error has occured: " @cors_preflight('GET,OPTIONS') @API.route('/foirecord//ministryrequest/') @@ -46,10 +47,10 @@ def get(requestid, ministryrequestid): try: result = recordservice().fetch(requestid, ministryrequestid) return json.dumps(result), 200 - except KeyError as err: - return {'status': False, 'message':err.messages}, 400 + except KeyError as error: + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except Exception as exception: - return {'status': exception.status_code, 'message':exception.message}, 500 + return {'status': False, 'message': str(exception)}, 500 @cors_preflight('POST,OPTIONS') @API.route('/foirecord//ministryrequest/') @@ -69,8 +70,8 @@ def post(requestid, ministryrequestid): response = recordservice().create(requestid, ministryrequestid, recordschema, AuthHelper.getuserid()) respcode = 200 if response.success == True else 500 return {'status': response.success, 'message':response.message,'data': response.args[0]} , respcode - except KeyError as err: - return {'status': False, 'message':err.messages}, 400 + except KeyError as error: + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -91,8 +92,8 @@ def post(requestid, ministryrequestid): data = FOIRequestRecordUpdateSchema().load(requestjson) result = recordservice().update(requestid, ministryrequestid, data, AuthHelper.getuserid()) return {'status': result.success, 'message':result.message,'id':result.identifier} , 200 - except KeyError as err: - return {'status': False, 'message':err['messages']}, 400 + except KeyError as error: + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -112,8 +113,8 @@ def post(requestid, ministryrequestid): recordschema = FOIRequestBulkRetryRecordSchema().load(requestjson, unknown=INCLUDE) result = recordservice().retry(requestid, ministryrequestid, recordschema) return {'status': result.success, 'message':result.message,'id':result.identifier} , 200 - except KeyError as err: - return {'status': False, 'message':err.messages}, 400 + except KeyError as error: + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -134,8 +135,8 @@ def post(requestid, ministryrequestid,recordid): result = recordservice().replace(requestid, ministryrequestid,recordid, recordschema,AuthHelper.getuserid()) return {'status': result.success, 'message':result.message,'id':result.identifier} , 200 - except KeyError as err: - return {'status': False, 'message':err.messages}, 400 + except KeyError as error: + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -157,8 +158,8 @@ def post(requestid, ministryrequestid, recordstype): response = recordservice().triggerpdfstitchservice(requestid, ministryrequestid, recordschema, AuthHelper.getuserid()) respcode = 200 if response.success == True else 500 return {'status': response.success, 'message':response.message,'id':response.identifier}, respcode - except KeyError as err: - return {'status': False, 'message':err.messages}, 400 + except KeyError as error: + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -177,8 +178,8 @@ def get(requestid, ministryrequestid, recordstype): try: result = recordservice().getpdfstitchpackagetodownload(ministryrequestid, recordstype.lower()) return json.dumps(result), 200 - except KeyError as err: - return {'status': False, 'message':err.messages}, 400 + except KeyError as error: + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -198,15 +199,15 @@ def get(requestid, ministryrequestid, recordstype): result = recordservice().getpdfstichstatus(ministryrequestid, recordstype.lower()) #("getpdfstichstatus result == ", result) return result, 200 - except KeyError as err: - print("KeyError == ", err.messages) - return {'status': False, 'message':err.messages}, 400 + except KeyError as error: + print(CUSTOM_KEYERROR_MESSAGE + str(error)) + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: print("BusinessException == ", exception.message) return {'status': exception.status_code, 'message':exception.message}, 500 except Exception as error: print("Exception error == ", error) - return {'status': False, 'message':error.message}, 500 + return {'status': False, 'message': str(error)}, 500 @cors_preflight('GET,OPTIONS') @API.route('/foirecord//ministryrequest///recrodschanged') @@ -224,12 +225,12 @@ def get(requestid, ministryrequestid, recordstype): result = recordservice().isrecordschanged(ministryrequestid, recordstype.lower()) #print("records changed == ", result) return result, 200 - except KeyError as err: - print("KeyError == ", err.messages) - return {'status': False, 'message':err.messages}, 400 + except KeyError as error: + print(CUSTOM_KEYERROR_MESSAGE + str(error)) + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: print("BusinessException == ", exception.message) return {'status': exception.status_code, 'message':exception.message}, 500 except Exception as error: print("Exception error == ", error) - return {'status': False, 'message':error.message}, 500 \ No newline at end of file + return {'status': False, 'message': str(error)}, 500 \ No newline at end of file diff --git a/request-management-api/request_api/resources/foirequest.py b/request-management-api/request_api/resources/foirequest.py index 4ccb5aff3..8d33fd0f6 100644 --- a/request-management-api/request_api/resources/foirequest.py +++ b/request-management-api/request_api/resources/foirequest.py @@ -36,6 +36,7 @@ API = Namespace('FOIRequests', description='Endpoints for FOI request management') TRACER = Tracer.get_instance() EXCEPTION_MESSAGE_NOTFOUND_REQUEST='Record not found' +CUSTOM_KEYERROR_MESSAGE = "Key error has occured: " @cors_preflight('GET,OPTIONS') @@ -72,8 +73,8 @@ def get(foirequestid,foiministryrequestid,usertype = None): return jsondata , statuscode except ValueError: return {'status': 500, 'message':"Invalid Request Id"}, 500 - except KeyError as err: - return {'status': False, 'message':err.messages}, 400 + except KeyError as error: + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -117,9 +118,9 @@ def post(): return {'status': result.success, 'message':result.message,'id':result.identifier, 'ministryRequests': result.args[0]} , 200 except ValidationError as err: - return {'status': False, 'message':err.messages}, 400 - except KeyError as err: - return {'status': False, 'message':err.messages}, 400 + return {'status': False, 'message': str(err)}, 400 + except KeyError as error: + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -146,9 +147,9 @@ def post(foirequestid,foiministryrequestid): else: return {'status': False, 'message':EXCEPTION_MESSAGE_NOTFOUND_REQUEST,'id':foirequestid} , 404 except ValidationError as err: - return {'status': False, 'message':err.messages}, 400 - except KeyError as err: - return {'status': False, 'message':err.messages}, 400 + return {'status': False, 'message': str(err)}, 400 + except KeyError as error: + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -186,9 +187,9 @@ def post(foirequestid,foiministryrequestid,actiontype = None,usertype = None): else: return {'status': False, 'message':EXCEPTION_MESSAGE_NOTFOUND_REQUEST,'id':foirequestid} , 404 except ValidationError as err: - return {'status': False, 'message':err.messages}, 400 - except KeyError as err: - return {'status': False, 'message':err.messages}, 400 + return {'status': False, 'message': str(err)}, 400 + except KeyError as error: + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -224,7 +225,7 @@ def put(foirequestid): else: return {'status': False, 'message':EXCEPTION_MESSAGE_NOTFOUND_REQUEST,'id':foirequestid} , 404 except ValidationError as err: - return {'status': False, 'message':err.messages}, 40 + return {'status': False, 'message': str(err)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -246,8 +247,8 @@ def get(foirequestid, foiministryrequestid): return jsondata , statuscode except ValueError: return {'status': 500, 'message':"Invalid Request Id"}, 500 - except KeyError as err: - return {'status': False, 'message':err.messages}, 400 + except KeyError as error: + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -271,7 +272,7 @@ def post(ministryrequestid=None,type=None): else: return {'status': result.success, 'message':result.message,'id':result.identifier} , 500 except ValueError: - return {'status': 500, 'message':"Invalid Request"}, 400 + return {'status': 500, 'message':"Invalid Request"}, 500 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -287,6 +288,6 @@ def get(ministryrequestid,usertype=None): try : return FOIRequest.get(requestservice().getrequestid(ministryrequestid), ministryrequestid, usertype) except ValueError: - return {'status': 500, 'message':"Invalid Request"}, 400 + return {'status': 500, 'message':"Invalid Request"}, 500 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 \ No newline at end of file diff --git a/request-management-api/request_api/resources/foiwatcher.py b/request-management-api/request_api/resources/foiwatcher.py index 70a16e0f3..bde512c42 100644 --- a/request-management-api/request_api/resources/foiwatcher.py +++ b/request-management-api/request_api/resources/foiwatcher.py @@ -32,6 +32,7 @@ API = Namespace('FOIWatcher', description='Endpoints for FOI watcher management') TRACER = Tracer.get_instance() +CUSTOM_KEYERROR_MESSAGE = "Key error has occured: " @cors_preflight('GET,OPTIONS') @API.route('/foiwatcher/rawrequest/') @@ -48,9 +49,9 @@ def get(requestid): result = watcherservice().getrawrequestwatchers(requestid) return json.dumps(result), 200 except ValueError as err: - return {'status': 500, 'message':err.messages}, 500 - except KeyError as err: - return {'status': False, 'message':err.messages}, 400 + return {'status': 500, 'message': str(err)}, 500 + except KeyError as error: + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -72,8 +73,8 @@ def post(): if result.success == True: eventservice().posteventforwatcher(requestjson["requestid"], requestjson, "rawrequest",AuthHelper.getuserid(), AuthHelper.getusername()) return {'status': result.success, 'message':result.message} , 200 - except KeyError as err: - return {'status': False, 'message':err.messages}, 400 + except KeyError as error: + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -91,8 +92,8 @@ def put(requestid): try: result = watcherservice().disablerawrequestwatchers(requestid, AuthHelper.getuserid()) return {'status': result.success, 'message':result.message,'id':result.identifier} , 200 - except KeyError as err: - return {'status': False, 'message':err.messages}, 400 + except KeyError as error: + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -110,8 +111,8 @@ def get(ministryrequestid): try: result = watcherservice().getministryrequestwatchers(ministryrequestid,AuthHelper.isministrymember()) return json.dumps(result), 200 - except KeyError as err: - return {'status': False, 'message':err.messages}, 400 + except KeyError as error: + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -133,8 +134,8 @@ def post(): if result.success == True: eventservice().posteventforwatcher(requestjson["ministryrequestid"], requestjson, "ministryrequest", AuthHelper.getuserid(), AuthHelper.getusername()) return {'status': result.success, 'message':result.message} , 200 - except KeyError as err: - return {'status': False, 'message':err.messages}, 400 + except KeyError as error: + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -152,7 +153,7 @@ def put(ministryrequestid): try: result = watcherservice().disableministryrequestwatchers(ministryrequestid, AuthHelper.getuserid()) return {'status': result.success, 'message':result.message,'id':result.identifier} , 200 - except KeyError as err: - return {'status': False, 'message':err.messages}, 400 + except KeyError as error: + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 \ No newline at end of file diff --git a/request-management-api/request_api/resources/foiworkflow.py b/request-management-api/request_api/resources/foiworkflow.py index ccb2a0fa7..a58503a73 100644 --- a/request-management-api/request_api/resources/foiworkflow.py +++ b/request-management-api/request_api/resources/foiworkflow.py @@ -29,6 +29,7 @@ API = Namespace('FOIWorkflow', description='Endpoints for FOI workflow management') TRACER = Tracer.get_instance() +CUSTOM_KEYERROR_MESSAGE = "Key error has occured: " @cors_preflight('POST,OPTIONS') @API.route('/foiworkflow///sync') @@ -46,9 +47,9 @@ def post(requesttype, requestid): response = workflowservice().syncwfinstance(requesttype, requestid, True) return json.dumps({"message": str(response)}), 200 except ValueError as err: - return {'status': 500, 'message':err.messages}, 500 - except KeyError as err: - return {'status': False, 'message':err.messages}, 400 + return {'status': 500, 'message': str(err)}, 500 + except KeyError as error: + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 diff --git a/request-management-api/request_api/services/rawrequestservice.py b/request-management-api/request_api/services/rawrequestservice.py index 594932595..6abaf1ff1 100644 --- a/request-management-api/request_api/services/rawrequestservice.py +++ b/request-management-api/request_api/services/rawrequestservice.py @@ -68,7 +68,7 @@ def saverawrequest(self, requestdatajson, sourceofsubmission, userid,notes): try: workflowservice().createinstance(redispubservice.foirequestqueueredischannel, json_data) except Exception as ex: - logging.error("Unable to create instance", ex) + logging.error(ex) asyncio.ensure_future(redispubservice.publishrequest(json_data)) return result diff --git a/request-management-api/request_api/services/workflowservice.py b/request-management-api/request_api/services/workflowservice.py index 14bd0f35a..f4b6f81a0 100644 --- a/request-management-api/request_api/services/workflowservice.py +++ b/request-management-api/request_api/services/workflowservice.py @@ -2,7 +2,7 @@ import os import json from enum import Enum -from request_api.exceptions import BusinessException +from request_api.exceptions import BusinessException, Error from request_api.utils.redispublisher import RedisPublisherService from request_api.services.external.bpmservice import MessageType, bpmservice, ProcessDefinitionKey from request_api.services.cfrfeeservice import cfrfeeservice @@ -26,7 +26,7 @@ class workflowservice: def createinstance(self, definitionkey, message): response = bpmservice().createinstance(definitionkey, json.loads(message)) if response is None: - raise BusinessException("Unable to create instance for key"+ definitionkey) + raise Exception("Unable to create instance for key"+ definitionkey) return response def postunopenedevent(self, id, wfinstanceid, requestsschema, status, ministries=None): diff --git a/request-management-api/request_api/tracer.py b/request-management-api/request_api/tracer.py index 80815410b..e88efcee9 100644 --- a/request-management-api/request_api/tracer.py +++ b/request-management-api/request_api/tracer.py @@ -34,7 +34,7 @@ def get_instance(): def __init__(self): """Virtually private constructor.""" if Tracer.__instance is not None: - raise BusinessException('Attempt made to create multiple tracing instances') + raise Exception('Attempt made to create multiple tracing instances') api_tracer = ApiTracer() Tracer.__instance = ApiTracing(api_tracer.tracer) diff --git a/request-management-api/request_api/utils/redispublisher.py b/request-management-api/request_api/utils/redispublisher.py index dab04e31a..0cb8a1ff8 100644 --- a/request-management-api/request_api/utils/redispublisher.py +++ b/request-management-api/request_api/utils/redispublisher.py @@ -22,7 +22,7 @@ def publishcommment(self, message): logging.info(message) self.publishtoredischannel(self.foicommentqueueredischannel, message) except Exception as ex: - current_app.logger.error("%s,%s" % ('Unable to get user details', ex.message)) + current_app.logger.error("%s,%s" % ('Unable to get user details', ex)) raise ex def publishtoredischannel(self, channel , message):