From 8284a976d755398155cf0ffb15c50346c88093dc Mon Sep 17 00:00:00 2001 From: Aman-Hundal Date: Tue, 17 Oct 2023 16:38:51 -0700 Subject: [PATCH 1/5] cherry picked and merged commit 71fe9a5906fca1fdcbe6f82b2156b4e0f8ed8c2e to local branch --- .../request_api/resources/foiadmin.py | 18 +++--- .../request_api/resources/foicfrfee.py | 8 +-- .../request_api/resources/foicomment.py | 20 +++---- .../request_api/resources/foidocument.py | 58 +++++++++++++++---- .../request_api/resources/foiemail.py | 8 +-- .../request_api/resources/foiextension.py | 24 ++++---- .../request_api/resources/foinotification.py | 16 ++--- .../request_api/resources/foipayment.py | 12 ++-- .../request_api/resources/foirecord.py | 44 +++++++------- .../request_api/resources/foirequest.py | 20 +++---- .../request_api/resources/foiwatcher.py | 24 ++++---- .../request_api/resources/foiworkflow.py | 4 +- .../request_api/services/rawrequestservice.py | 2 +- .../request_api/services/workflowservice.py | 4 +- 14 files changed, 150 insertions(+), 112 deletions(-) diff --git a/request-management-api/request_api/resources/foiadmin.py b/request-management-api/request_api/resources/foiadmin.py index 864157ec4..2e83e7cf5 100644 --- a/request-management-api/request_api/resources/foiadmin.py +++ b/request-management-api/request_api/resources/foiadmin.py @@ -50,9 +50,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': f"{error=}"}, 400 + except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @cors_preflight('POST,OPTIONS') @@ -73,8 +73,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': f"{error=}"}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -97,8 +97,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': f"{error=}"}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -118,8 +118,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': f"{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..1305b20df 100644 --- a/request-management-api/request_api/resources/foicfrfee.py +++ b/request-management-api/request_api/resources/foicfrfee.py @@ -59,7 +59,7 @@ def post(requestid, ministryrequestid): logging.error(verr) return {'status': False, 'message':verr.messages}, 400 except KeyError as err: - logging.error(err) + logging.error(type(err)) return {'status': False, 'message': EXCEPTION_MESSAGE_BAD_REQUEST}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -89,7 +89,7 @@ def post(requestid, ministryrequestid): logging.error(verr) return {'status': False, 'message':verr.messages}, 400 except KeyError as err: - logging.error(err) + logging.error(type(err)) return {'status': False, 'message': EXCEPTION_MESSAGE_BAD_REQUEST}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -109,7 +109,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': f"{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..de88e08da 100644 --- a/request-management-api/request_api/resources/foicomment.py +++ b/request-management-api/request_api/resources/foicomment.py @@ -54,8 +54,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': f"{error=}"}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -77,8 +77,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': f"{error=}"}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -108,8 +108,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': f"{error=}"}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -136,8 +136,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': f"{error=}"}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -166,8 +166,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': f"{error=}"}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 diff --git a/request-management-api/request_api/resources/foidocument.py b/request-management-api/request_api/resources/foidocument.py index f095f9444..725b00103 100644 --- a/request-management-api/request_api/resources/foidocument.py +++ b/request-management-api/request_api/resources/foidocument.py @@ -49,8 +49,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': f"{error=}"}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -74,8 +74,8 @@ def post(requestid, 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 + except KeyError as error: + return {'status': False, 'message': f"{error=}"}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -98,11 +98,49 @@ def post(requestid, documentid, 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 + except KeyError as error: + return {'status': False, 'message': f"{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':err.messages}, 400 + except KeyError as error: + return {'status': False, 'message': f"{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): @@ -121,8 +159,8 @@ def post(requestid, documentid, 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 + except KeyError as error: + return {'status': False, 'message': f"{error=}"}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -141,7 +179,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': f"{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..ca9cab211 100644 --- a/request-management-api/request_api/resources/foiemail.py +++ b/request-management-api/request_api/resources/foiemail.py @@ -51,8 +51,8 @@ def post(requestid, ministryrequestid, servicename): 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 + except KeyError as error: + return {'status': False, 'message': f"{error=}"}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -72,8 +72,8 @@ def post(requestid, ministryrequestid, servicename): 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 + except KeyError as error: + return {'status': False, 'message': f"{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..faab268a7 100644 --- a/request-management-api/request_api/resources/foiextension.py +++ b/request-management-api/request_api/resources/foiextension.py @@ -52,8 +52,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': f"{error=}"}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -71,8 +71,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': f"{error=}"}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -96,8 +96,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': f"{error=}"}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -121,8 +121,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': f"{error=}"}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -145,8 +145,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': f"{error=}"}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -167,7 +167,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': f"{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..1e597096d 100644 --- a/request-management-api/request_api/resources/foinotification.py +++ b/request-management-api/request_api/resources/foinotification.py @@ -47,8 +47,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': f"{error=}"}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -72,8 +72,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': f"{error=}"}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -92,8 +92,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': f"{error=}"}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -113,7 +113,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': f"{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..da3d73399 100644 --- a/request-management-api/request_api/resources/foipayment.py +++ b/request-management-api/request_api/resources/foipayment.py @@ -48,8 +48,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': f"{error=}"}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -69,8 +69,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': f"{error=}"}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -88,8 +88,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': f"{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..b5220904c 100644 --- a/request-management-api/request_api/resources/foirecord.py +++ b/request-management-api/request_api/resources/foirecord.py @@ -46,8 +46,8 @@ 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': f"{error=}"}, 400 except Exception as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -69,8 +69,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': f"{error=}"}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -91,8 +91,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': f"{error=}"}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -112,8 +112,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': f"{error=}"}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -134,8 +134,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': f"{error=}"}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -157,8 +157,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': f"{error=}"}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -177,8 +177,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': f"{error=}"}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -198,15 +198,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("KeyError") + return {'status': False, 'message': f"{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': f"{error=}"}, 500 @cors_preflight('GET,OPTIONS') @API.route('/foirecord//ministryrequest///recrodschanged') @@ -224,12 +224,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("KeyError") + return {'status': False, 'message': f"{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': f"{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..ec1d67fb1 100644 --- a/request-management-api/request_api/resources/foirequest.py +++ b/request-management-api/request_api/resources/foirequest.py @@ -72,8 +72,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': f"{error=}"}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -118,8 +118,8 @@ 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 + except KeyError as error: + return {'status': False, 'message': f"{error=}"}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -147,8 +147,8 @@ def post(foirequestid,foiministryrequestid): 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 + except KeyError as error: + return {'status': False, 'message': f"{error=}"}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -187,8 +187,8 @@ def post(foirequestid,foiministryrequestid,actiontype = None,usertype = None): 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 + except KeyError as error: + return {'status': False, 'message': f"{error=}"}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -246,8 +246,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': f"{error=}"}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 diff --git a/request-management-api/request_api/resources/foiwatcher.py b/request-management-api/request_api/resources/foiwatcher.py index 70a16e0f3..78750acbd 100644 --- a/request-management-api/request_api/resources/foiwatcher.py +++ b/request-management-api/request_api/resources/foiwatcher.py @@ -49,8 +49,8 @@ def get(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 + except KeyError as error: + return {'status': False, 'message': f"{error=}"}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -72,8 +72,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': f"{error=}"}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -91,8 +91,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': f"{error=}"}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -110,8 +110,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': f"{error=}"}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -133,8 +133,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': f"{error=}"}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -152,7 +152,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': f"{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..006ac55cc 100644 --- a/request-management-api/request_api/resources/foiworkflow.py +++ b/request-management-api/request_api/resources/foiworkflow.py @@ -47,8 +47,8 @@ def post(requesttype, requestid): 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 + except KeyError as error: + return {'status': False, 'message': f"{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..c72d3ccf1 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("Unable to create instance") 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..e3faaf143 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 BusinessException(Error.INVALID_INPUT) return response def postunopenedevent(self, id, wfinstanceid, requestsschema, status, ministries=None): From 0ff1d2f0972ea8ab21e59d44340a17bd0830ff1b Mon Sep 17 00:00:00 2001 From: Aman-Hundal Date: Tue, 17 Oct 2023 17:15:38 -0700 Subject: [PATCH 2/5] Validation exceptions take a message arg and therefore .messages is not a valid k:v pairs for validation exceptions --- request-management-api/request_api/resources/foicfrfee.py | 4 ++-- .../request_api/resources/foidocument.py | 8 ++++---- .../request_api/resources/foirequest.py | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/request-management-api/request_api/resources/foicfrfee.py b/request-management-api/request_api/resources/foicfrfee.py index 1305b20df..8c925f4e7 100644 --- a/request-management-api/request_api/resources/foicfrfee.py +++ b/request-management-api/request_api/resources/foicfrfee.py @@ -57,7 +57,7 @@ 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 + return {'status': False, 'message': verr}, 400 except KeyError as err: logging.error(type(err)) return {'status': False, 'message': EXCEPTION_MESSAGE_BAD_REQUEST}, 400 @@ -87,7 +87,7 @@ 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 + return {'status': False, 'message': verr}, 400 except KeyError as err: logging.error(type(err)) return {'status': False, 'message': EXCEPTION_MESSAGE_BAD_REQUEST}, 400 diff --git a/request-management-api/request_api/resources/foidocument.py b/request-management-api/request_api/resources/foidocument.py index 725b00103..7df6c32dc 100644 --- a/request-management-api/request_api/resources/foidocument.py +++ b/request-management-api/request_api/resources/foidocument.py @@ -73,7 +73,7 @@ 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 + return {'status': False, 'message': err}, 400 except KeyError as error: return {'status': False, 'message': f"{error=}"}, 400 except BusinessException as exception: @@ -97,7 +97,7 @@ 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 + return {'status': False, 'message': err}, 400 except KeyError as error: return {'status': False, 'message': f"{error=}"}, 400 except BusinessException as exception: @@ -135,7 +135,7 @@ def post(requesttype, requestid, documentid): 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':err.messages}, 400 + return {'status': False, 'message': err}, 400 except KeyError as error: return {'status': False, 'message': f"{error=}"}, 400 except BusinessException as exception: @@ -158,7 +158,7 @@ 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 + return {'status': False, 'message': err}, 400 except KeyError as error: return {'status': False, 'message': f"{error=}"}, 400 except BusinessException as exception: diff --git a/request-management-api/request_api/resources/foirequest.py b/request-management-api/request_api/resources/foirequest.py index ec1d67fb1..c7d87aa6c 100644 --- a/request-management-api/request_api/resources/foirequest.py +++ b/request-management-api/request_api/resources/foirequest.py @@ -117,7 +117,7 @@ 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 + return {'status': False, 'message': err}, 400 except KeyError as error: return {'status': False, 'message': f"{error=}"}, 400 except BusinessException as exception: @@ -146,7 +146,7 @@ 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 + return {'status': False, 'message': err}, 400 except KeyError as error: return {'status': False, 'message': f"{error=}"}, 400 except BusinessException as exception: @@ -186,7 +186,7 @@ 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 + return {'status': False, 'message': err}, 400 except KeyError as error: return {'status': False, 'message': f"{error=}"}, 400 except BusinessException as exception: @@ -224,7 +224,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': err}, 40 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 From af60d65f55d40dfc3753fbd965c0fc243fc1e2a3 Mon Sep 17 00:00:00 2001 From: Aman-Hundal Date: Tue, 17 Oct 2023 17:40:53 -0700 Subject: [PATCH 3/5] Adjusted handling for keyerror messages --- .../request_api/resources/foiadmin.py | 8 +++---- .../request_api/resources/foicfrfee.py | 2 +- .../request_api/resources/foicomment.py | 10 ++++----- .../request_api/resources/foidocument.py | 12 +++++----- .../request_api/resources/foiemail.py | 4 ++-- .../request_api/resources/foiextension.py | 12 +++++----- .../request_api/resources/foinotification.py | 8 +++---- .../request_api/resources/foipayment.py | 6 ++--- .../request_api/resources/foirecord.py | 22 +++++++++---------- .../request_api/resources/foirequest.py | 10 ++++----- .../request_api/resources/foiwatcher.py | 12 +++++----- .../request_api/resources/foiworkflow.py | 2 +- 12 files changed, 54 insertions(+), 54 deletions(-) diff --git a/request-management-api/request_api/resources/foiadmin.py b/request-management-api/request_api/resources/foiadmin.py index 2e83e7cf5..98fff07f2 100644 --- a/request-management-api/request_api/resources/foiadmin.py +++ b/request-management-api/request_api/resources/foiadmin.py @@ -51,7 +51,7 @@ def get(): result = programareadivisionservice().getallprogramareadivisions() return json.dumps(result), 200 except KeyError as error: - return {'status': False, 'message': f"{error=}"}, 400 + return {'status': False, 'message': str(type(error).__name__)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -74,7 +74,7 @@ def post(): # asyncio.ensure_future(); return {'status': result.success, 'message':result.message, 'id':result.identifier}, 200 except KeyError as error: - return {'status': False, 'message': f"{error=}"}, 400 + return {'status': False, 'message': str(type(error).__name__)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -98,7 +98,7 @@ def put(divisionid): # asyncio.ensure_future(); return {'status': result.success, 'message':result.message, 'id':result.identifier}, 200 except KeyError as error: - return {'status': False, 'message': f"{error=}"}, 400 + return {'status': False, 'message': str(type(error).__name__)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -119,7 +119,7 @@ def put(divisionid): # asyncio.ensure_future(); return {'status': result.success, 'message':result.message, 'id':result.identifier}, 200 except KeyError as error: - return {'status': False, 'message': f"{error=}"}, 400 + return {'status': False, 'message': str(type(error).__name__)}, 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 8c925f4e7..37308c685 100644 --- a/request-management-api/request_api/resources/foicfrfee.py +++ b/request-management-api/request_api/resources/foicfrfee.py @@ -110,6 +110,6 @@ def get(requestid): result = {"current": cfrfeeservice().getcfrfee(requestid), "history": cfrfeeservice().getcfrfeehistory(requestid)} return json.dumps(result), 200 except KeyError as error: - return {'status': False, 'message': f"{error=}"}, 400 + return {'status': False, 'message': str(type(error).__name__)}, 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 de88e08da..866030b20 100644 --- a/request-management-api/request_api/resources/foicomment.py +++ b/request-management-api/request_api/resources/foicomment.py @@ -55,7 +55,7 @@ def post(): asyncio.ensure_future(eventservice().postcommentevent(result.identifier, "ministryrequest", AuthHelper.getuserid())) return {'status': result.success, 'message':result.message,'id':result.identifier} , 200 except KeyError as error: - return {'status': False, 'message': f"{error=}"}, 400 + return {'status': False, 'message': str(type(error).__name__)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -78,7 +78,7 @@ def post(): asyncio.ensure_future(eventservice().postcommentevent(result.identifier, "rawrequest", AuthHelper.getuserid())) return {'status': result.success, 'message':result.message,'id':result.identifier} , 200 except KeyError as error: - return {'status': False, 'message': f"{error=}"}, 400 + return {'status': False, 'message': str(type(error).__name__)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -109,7 +109,7 @@ def get(requesttype, requestid): else: return {'status': 401, 'message':'Restricted Request'} , 401 except KeyError as error: - return {'status': False, 'message': f"{error=}"}, 400 + return {'status': False, 'message': str(type(error).__name__)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -137,7 +137,7 @@ def put(requesttype, commentid): 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 error: - return {'status': False, 'message': f"{error=}"}, 400 + return {'status': False, 'message': str(type(error).__name__)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -167,7 +167,7 @@ def put(requesttype, commentid): 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 error: - return {'status': False, 'message': f"{error=}"}, 400 + return {'status': False, 'message': str(type(error).__name__)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 diff --git a/request-management-api/request_api/resources/foidocument.py b/request-management-api/request_api/resources/foidocument.py index 7df6c32dc..7e90db779 100644 --- a/request-management-api/request_api/resources/foidocument.py +++ b/request-management-api/request_api/resources/foidocument.py @@ -50,7 +50,7 @@ def get(requestid, requesttype): result = documentservice().getrequestdocumentsbyrole(requestid, requesttype, AuthHelper.isministrymember()) return json.dumps(result), 200 except KeyError as error: - return {'status': False, 'message': f"{error=}"}, 400 + return {'status': False, 'message': str(type(error).__name__)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -75,7 +75,7 @@ def post(requestid, requesttype): except ValidationError as err: return {'status': False, 'message': err}, 400 except KeyError as error: - return {'status': False, 'message': f"{error=}"}, 400 + return {'status': False, 'message': str(type(error).__name__)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -99,7 +99,7 @@ def post(requestid, documentid, requesttype): except ValidationError as err: return {'status': False, 'message': err}, 400 except KeyError as error: - return {'status': False, 'message': f"{error=}"}, 400 + return {'status': False, 'message': str(type(error).__name__)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -137,7 +137,7 @@ def post(requesttype, requestid, documentid): except ValidationError as err: return {'status': False, 'message': err}, 400 except KeyError as error: - return {'status': False, 'message': f"{error=}"}, 400 + return {'status': False, 'message': str(type(error).__name__)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -160,7 +160,7 @@ def post(requestid, documentid, requesttype): except ValidationError as err: return {'status': False, 'message': err}, 400 except KeyError as error: - return {'status': False, 'message': f"{error=}"}, 400 + return {'status': False, 'message': str(type(error).__name__)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -180,6 +180,6 @@ def post(requestid, documentid, requesttype): result = documentservice().deleterequestdocument(requestid, documentid, AuthHelper.getuserid(), requesttype) return {'status': result.success, 'message':result.message,'id':result.identifier} , 200 except KeyError as error: - return {'status': False, 'message': f"{error=}"}, 400 + return {'status': False, 'message': str(type(error).__name__)}, 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 ca9cab211..0c590be23 100644 --- a/request-management-api/request_api/resources/foiemail.py +++ b/request-management-api/request_api/resources/foiemail.py @@ -52,7 +52,7 @@ def post(requestid, ministryrequestid, servicename): except ValueError as err: return {'status': 500, 'message':err.messages}, 500 except KeyError as error: - return {'status': False, 'message': f"{error=}"}, 400 + return {'status': False, 'message': str(type(error).__name__)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -73,7 +73,7 @@ def post(requestid, ministryrequestid, servicename): except ValueError as err: return {'status': 500, 'message':err.messages}, 500 except KeyError as error: - return {'status': False, 'message': f"{error=}"}, 400 + return {'status': False, 'message': str(type(error).__name__)}, 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 faab268a7..b985cc477 100644 --- a/request-management-api/request_api/resources/foiextension.py +++ b/request-management-api/request_api/resources/foiextension.py @@ -53,7 +53,7 @@ def get(requestid): extensionrecords = extensionservice().getrequestextensions(requestid) return json.dumps(extensionrecords), 200 except KeyError as error: - return {'status': False, 'message': f"{error=}"}, 400 + return {'status': False, 'message': str(type(error).__name__)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -72,7 +72,7 @@ def get(extensionid): extensionrecord = extensionservice().getrequestextension(extensionid) return json.dumps(extensionrecord), 200 except KeyError as error: - return {'status': False, 'message': f"{error=}"}, 400 + return {'status': False, 'message': str(type(error).__name__)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -97,7 +97,7 @@ def post(requestid, ministryrequestid): newduedate, = result.args return {'status': result.success, 'message':result.message,'id':result.identifier, 'newduedate': newduedate or None} , 200 except KeyError as error: - return {'status': False, 'message': f"{error=}"}, 400 + return {'status': False, 'message': str(type(error).__name__)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -122,7 +122,7 @@ def post(ministryrequestid): eventservice().posteventforaxisextension(ministryrequestid, result.args[0], AuthHelper.getuserid(), AuthHelper.getusername(), "add") return {'status': result.success, 'message':result.message} , 200 except KeyError as error: - return {'status': False, 'message': f"{error=}"}, 400 + return {'status': False, 'message': str(type(error).__name__)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -146,7 +146,7 @@ def post(requestid, ministryrequestid, extensionid): 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 error: - return {'status': False, 'message': f"{error=}"}, 400 + return {'status': False, 'message': str(type(error).__name__)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -168,6 +168,6 @@ def post(requestid, ministryrequestid, extensionid): 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 error: - return {'status': False, 'message': f"{error=}"}, 400 + return {'status': False, 'message': str(type(error).__name__)}, 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 1e597096d..4967f31ab 100644 --- a/request-management-api/request_api/resources/foinotification.py +++ b/request-management-api/request_api/resources/foinotification.py @@ -48,7 +48,7 @@ def get(): except ValueError: return {'status': 500, 'message':"Invalid Request Id"}, 500 except KeyError as error: - return {'status': False, 'message': f"{error=}"}, 400 + return {'status': False, 'message': str(type(error).__name__)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -73,7 +73,7 @@ def delete(type=None,idnumber=None,notficationid=None): except ValueError: return {'status': 500, 'message':"Invalid Request Id"}, 500 except KeyError as error: - return {'status': False, 'message': f"{error=}"}, 400 + return {'status': False, 'message': str(type(error).__name__)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -93,7 +93,7 @@ def post(): respcode = 200 if reminderresponse.success == True else 500 return {'status': reminderresponse.success, 'message':reminderresponse.message,'id': reminderresponse.identifier} , respcode except KeyError as error: - return {'status': False, 'message': f"{error=}"}, 400 + return {'status': False, 'message': str(type(error).__name__)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -114,6 +114,6 @@ def post(request_id: int, ministry_request_id: int): respcode = 200 if reminderresponse.success == True else 500 return {'status': reminderresponse.success, 'message':reminderresponse.message,'id': reminderresponse.identifier} , respcode except KeyError as error: - return {'status': False, 'message': f"{error=}"}, 400 + return {'status': False, 'message': str(type(error).__name__)}, 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 da3d73399..b637d0772 100644 --- a/request-management-api/request_api/resources/foipayment.py +++ b/request-management-api/request_api/resources/foipayment.py @@ -49,7 +49,7 @@ def post(requestid, ministryrequestid): result = paymentservice().createpayment(requestid, ministryrequestid, paymentschema) return {'status': result.success, 'message':result.message,'id':result.identifier} , 200 except KeyError as error: - return {'status': False, 'message': f"{error=}"}, 400 + return {'status': False, 'message': str(type(error).__name__)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -70,7 +70,7 @@ def post(requestid, ministryrequestid): result = paymentservice().cancelpayment(requestid, ministryrequestid, paymentschema) return {'status': result.success, 'message':result.message,'id':result.identifier} , 200 except KeyError as error: - return {'status': False, 'message': f"{error=}"}, 400 + return {'status': False, 'message': str(type(error).__name__)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -89,7 +89,7 @@ def get(requestid, ministryrequestid): result = paymentservice().getpayment(requestid, ministryrequestid) return json.dumps(result), 200 except KeyError as error: - return {'status': False, 'message': f"{error=}"}, 400 + return {'status': False, 'message': str(type(error).__name__)}, 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 b5220904c..a146b1a4f 100644 --- a/request-management-api/request_api/resources/foirecord.py +++ b/request-management-api/request_api/resources/foirecord.py @@ -47,7 +47,7 @@ def get(requestid, ministryrequestid): result = recordservice().fetch(requestid, ministryrequestid) return json.dumps(result), 200 except KeyError as error: - return {'status': False, 'message': f"{error=}"}, 400 + return {'status': False, 'message': str(type(error).__name__)}, 400 except Exception as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -70,7 +70,7 @@ def post(requestid, ministryrequestid): respcode = 200 if response.success == True else 500 return {'status': response.success, 'message':response.message,'data': response.args[0]} , respcode except KeyError as error: - return {'status': False, 'message': f"{error=}"}, 400 + return {'status': False, 'message': str(type(error).__name__)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -92,7 +92,7 @@ def post(requestid, ministryrequestid): result = recordservice().update(requestid, ministryrequestid, data, AuthHelper.getuserid()) return {'status': result.success, 'message':result.message,'id':result.identifier} , 200 except KeyError as error: - return {'status': False, 'message': f"{error=}"}, 400 + return {'status': False, 'message': str(type(error).__name__)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -113,7 +113,7 @@ def post(requestid, ministryrequestid): result = recordservice().retry(requestid, ministryrequestid, recordschema) return {'status': result.success, 'message':result.message,'id':result.identifier} , 200 except KeyError as error: - return {'status': False, 'message': f"{error=}"}, 400 + return {'status': False, 'message': str(type(error).__name__)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -135,7 +135,7 @@ def post(requestid, ministryrequestid,recordid): return {'status': result.success, 'message':result.message,'id':result.identifier} , 200 except KeyError as error: - return {'status': False, 'message': f"{error=}"}, 400 + return {'status': False, 'message': str(type(error).__name__)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -158,7 +158,7 @@ def post(requestid, ministryrequestid, recordstype): respcode = 200 if response.success == True else 500 return {'status': response.success, 'message':response.message,'id':response.identifier}, respcode except KeyError as error: - return {'status': False, 'message': f"{error=}"}, 400 + return {'status': False, 'message': str(type(error).__name__)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -178,7 +178,7 @@ def get(requestid, ministryrequestid, recordstype): result = recordservice().getpdfstitchpackagetodownload(ministryrequestid, recordstype.lower()) return json.dumps(result), 200 except KeyError as error: - return {'status': False, 'message': f"{error=}"}, 400 + return {'status': False, 'message': str(type(error).__name__)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -199,8 +199,8 @@ def get(requestid, ministryrequestid, recordstype): #("getpdfstichstatus result == ", result) return result, 200 except KeyError as error: - print("KeyError") - return {'status': False, 'message': f"{error=}"}, 400 + print(str(type(error).__name__)) + return {'status': False, 'message': str(type(error).__name__)}, 400 except BusinessException as exception: print("BusinessException == ", exception.message) return {'status': exception.status_code, 'message':exception.message}, 500 @@ -225,8 +225,8 @@ def get(requestid, ministryrequestid, recordstype): #print("records changed == ", result) return result, 200 except KeyError as error: - print("KeyError") - return {'status': False, 'message': f"{error=}"}, 400 + print(str(type(error).__name__)) + return {'status': False, 'message': str(type(error).__name__)}, 400 except BusinessException as exception: print("BusinessException == ", exception.message) return {'status': exception.status_code, 'message':exception.message}, 500 diff --git a/request-management-api/request_api/resources/foirequest.py b/request-management-api/request_api/resources/foirequest.py index c7d87aa6c..f161841f5 100644 --- a/request-management-api/request_api/resources/foirequest.py +++ b/request-management-api/request_api/resources/foirequest.py @@ -73,7 +73,7 @@ def get(foirequestid,foiministryrequestid,usertype = None): except ValueError: return {'status': 500, 'message':"Invalid Request Id"}, 500 except KeyError as error: - return {'status': False, 'message': f"{error=}"}, 400 + return {'status': False, 'message': str(type(error).__name__)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -119,7 +119,7 @@ def post(): except ValidationError as err: return {'status': False, 'message': err}, 400 except KeyError as error: - return {'status': False, 'message': f"{error=}"}, 400 + return {'status': False, 'message': str(type(error).__name__)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -148,7 +148,7 @@ def post(foirequestid,foiministryrequestid): except ValidationError as err: return {'status': False, 'message': err}, 400 except KeyError as error: - return {'status': False, 'message': f"{error=}"}, 400 + return {'status': False, 'message': str(type(error).__name__)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -188,7 +188,7 @@ def post(foirequestid,foiministryrequestid,actiontype = None,usertype = None): except ValidationError as err: return {'status': False, 'message': err}, 400 except KeyError as error: - return {'status': False, 'message': f"{error=}"}, 400 + return {'status': False, 'message': str(type(error).__name__)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -247,7 +247,7 @@ def get(foirequestid, foiministryrequestid): except ValueError: return {'status': 500, 'message':"Invalid Request Id"}, 500 except KeyError as error: - return {'status': False, 'message': f"{error=}"}, 400 + return {'status': False, 'message': str(type(error).__name__)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 diff --git a/request-management-api/request_api/resources/foiwatcher.py b/request-management-api/request_api/resources/foiwatcher.py index 78750acbd..f96cb43c5 100644 --- a/request-management-api/request_api/resources/foiwatcher.py +++ b/request-management-api/request_api/resources/foiwatcher.py @@ -50,7 +50,7 @@ def get(requestid): except ValueError as err: return {'status': 500, 'message':err.messages}, 500 except KeyError as error: - return {'status': False, 'message': f"{error=}"}, 400 + return {'status': False, 'message': str(type(error).__name__)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -73,7 +73,7 @@ def post(): eventservice().posteventforwatcher(requestjson["requestid"], requestjson, "rawrequest",AuthHelper.getuserid(), AuthHelper.getusername()) return {'status': result.success, 'message':result.message} , 200 except KeyError as error: - return {'status': False, 'message': f"{error=}"}, 400 + return {'status': False, 'message': str(type(error).__name__)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -92,7 +92,7 @@ def put(requestid): result = watcherservice().disablerawrequestwatchers(requestid, AuthHelper.getuserid()) return {'status': result.success, 'message':result.message,'id':result.identifier} , 200 except KeyError as error: - return {'status': False, 'message': f"{error=}"}, 400 + return {'status': False, 'message': str(type(error).__name__)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -111,7 +111,7 @@ def get(ministryrequestid): result = watcherservice().getministryrequestwatchers(ministryrequestid,AuthHelper.isministrymember()) return json.dumps(result), 200 except KeyError as error: - return {'status': False, 'message': f"{error=}"}, 400 + return {'status': False, 'message': str(type(error).__name__)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -134,7 +134,7 @@ def post(): eventservice().posteventforwatcher(requestjson["ministryrequestid"], requestjson, "ministryrequest", AuthHelper.getuserid(), AuthHelper.getusername()) return {'status': result.success, 'message':result.message} , 200 except KeyError as error: - return {'status': False, 'message': f"{error=}"}, 400 + return {'status': False, 'message': str(type(error).__name__)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -153,6 +153,6 @@ def put(ministryrequestid): result = watcherservice().disableministryrequestwatchers(ministryrequestid, AuthHelper.getuserid()) return {'status': result.success, 'message':result.message,'id':result.identifier} , 200 except KeyError as error: - return {'status': False, 'message': f"{error=}"}, 400 + return {'status': False, 'message': str(type(error).__name__)}, 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 006ac55cc..71e5b68f8 100644 --- a/request-management-api/request_api/resources/foiworkflow.py +++ b/request-management-api/request_api/resources/foiworkflow.py @@ -48,7 +48,7 @@ def post(requesttype, requestid): except ValueError as err: return {'status': 500, 'message':err.messages}, 500 except KeyError as error: - return {'status': False, 'message': f"{error=}"}, 400 + return {'status': False, 'message': str(type(error).__name__)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 From 159bf0f0eaba18b1be8eba0162bdd10d79d2598f Mon Sep 17 00:00:00 2001 From: Aman-Hundal Date: Wed, 18 Oct 2023 14:19:03 -0700 Subject: [PATCH 4/5] Foi Flow exception handling fixed. WIP DocReviewer --- .../request_api/resources/foicfrfee.py | 8 ++++---- .../request_api/resources/foicomment.py | 4 ++-- .../request_api/resources/foidocument.py | 8 ++++---- .../request_api/resources/foiemail.py | 4 ++-- .../request_api/resources/foirecord.py | 6 +++--- .../request_api/resources/foirequest.py | 12 ++++++------ .../request_api/resources/foiwatcher.py | 2 +- .../request_api/resources/foiworkflow.py | 2 +- .../request_api/utils/redispublisher.py | 2 +- 9 files changed, 24 insertions(+), 24 deletions(-) diff --git a/request-management-api/request_api/resources/foicfrfee.py b/request-management-api/request_api/resources/foicfrfee.py index 37308c685..c8e36e801 100644 --- a/request-management-api/request_api/resources/foicfrfee.py +++ b/request-management-api/request_api/resources/foicfrfee.py @@ -57,9 +57,9 @@ 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}, 400 + return {'status': False, 'message': str(verr)}, 400 except KeyError as err: - logging.error(type(err)) + logging.error(str(type(err).__name__)) return {'status': False, 'message': EXCEPTION_MESSAGE_BAD_REQUEST}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -87,9 +87,9 @@ 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}, 400 + return {'status': False, 'message': str(verr)}, 400 except KeyError as err: - logging.error(type(err)) + logging.error(str(type(err).__name__)) return {'status': False, 'message': EXCEPTION_MESSAGE_BAD_REQUEST}, 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 866030b20..31ee32336 100644 --- a/request-management-api/request_api/resources/foicomment.py +++ b/request-management-api/request_api/resources/foicomment.py @@ -184,7 +184,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 +200,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 7e90db779..decf80ddb 100644 --- a/request-management-api/request_api/resources/foidocument.py +++ b/request-management-api/request_api/resources/foidocument.py @@ -73,7 +73,7 @@ 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}, 400 + return {'status': False, 'message': str(err)}, 400 except KeyError as error: return {'status': False, 'message': str(type(error).__name__)}, 400 except BusinessException as exception: @@ -97,7 +97,7 @@ 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}, 400 + return {'status': False, 'message': str(err)}, 400 except KeyError as error: return {'status': False, 'message': str(type(error).__name__)}, 400 except BusinessException as exception: @@ -135,7 +135,7 @@ def post(requesttype, requestid, documentid): 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': err}, 400 + return {'status': False, 'message': str(err)}, 400 except KeyError as error: return {'status': False, 'message': str(type(error).__name__)}, 400 except BusinessException as exception: @@ -158,7 +158,7 @@ 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}, 400 + return {'status': False, 'message': str(err)}, 400 except KeyError as error: return {'status': False, 'message': str(type(error).__name__)}, 400 except BusinessException as exception: diff --git a/request-management-api/request_api/resources/foiemail.py b/request-management-api/request_api/resources/foiemail.py index 0c590be23..143b280b1 100644 --- a/request-management-api/request_api/resources/foiemail.py +++ b/request-management-api/request_api/resources/foiemail.py @@ -50,7 +50,7 @@ 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 + return {'status': 500, 'message': str(err)}, 500 except KeyError as error: return {'status': False, 'message': str(type(error).__name__)}, 400 except BusinessException as exception: @@ -71,7 +71,7 @@ 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 + return {'status': 500, 'message': str(err)}, 500 except KeyError as error: return {'status': False, 'message': str(type(error).__name__)}, 400 except BusinessException as exception: diff --git a/request-management-api/request_api/resources/foirecord.py b/request-management-api/request_api/resources/foirecord.py index a146b1a4f..e90e9ae34 100644 --- a/request-management-api/request_api/resources/foirecord.py +++ b/request-management-api/request_api/resources/foirecord.py @@ -49,7 +49,7 @@ def get(requestid, ministryrequestid): except KeyError as error: return {'status': False, 'message': str(type(error).__name__)}, 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/') @@ -206,7 +206,7 @@ def get(requestid, ministryrequestid, recordstype): return {'status': exception.status_code, 'message':exception.message}, 500 except Exception as error: print("Exception error == ", error) - return {'status': False, 'message': f"{error=}"}, 500 + return {'status': False, 'message': str(error)}, 500 @cors_preflight('GET,OPTIONS') @API.route('/foirecord//ministryrequest///recrodschanged') @@ -232,4 +232,4 @@ def get(requestid, ministryrequestid, recordstype): return {'status': exception.status_code, 'message':exception.message}, 500 except Exception as error: print("Exception error == ", error) - return {'status': False, 'message': f"{error=}"}, 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 f161841f5..037e89a55 100644 --- a/request-management-api/request_api/resources/foirequest.py +++ b/request-management-api/request_api/resources/foirequest.py @@ -117,7 +117,7 @@ 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}, 400 + return {'status': False, 'message': str(err)}, 400 except KeyError as error: return {'status': False, 'message': str(type(error).__name__)}, 400 except BusinessException as exception: @@ -146,7 +146,7 @@ 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}, 400 + return {'status': False, 'message': str(err)}, 400 except KeyError as error: return {'status': False, 'message': str(type(error).__name__)}, 400 except BusinessException as exception: @@ -186,7 +186,7 @@ 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}, 400 + return {'status': False, 'message': str(err)}, 400 except KeyError as error: return {'status': False, 'message': str(type(error).__name__)}, 400 except BusinessException as exception: @@ -224,7 +224,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}, 40 + return {'status': False, 'message': str(err)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -271,7 +271,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 +287,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 f96cb43c5..065ba1154 100644 --- a/request-management-api/request_api/resources/foiwatcher.py +++ b/request-management-api/request_api/resources/foiwatcher.py @@ -48,7 +48,7 @@ def get(requestid): result = watcherservice().getrawrequestwatchers(requestid) return json.dumps(result), 200 except ValueError as err: - return {'status': 500, 'message':err.messages}, 500 + return {'status': 500, 'message': str(err)}, 500 except KeyError as error: return {'status': False, 'message': str(type(error).__name__)}, 400 except BusinessException as exception: diff --git a/request-management-api/request_api/resources/foiworkflow.py b/request-management-api/request_api/resources/foiworkflow.py index 71e5b68f8..e22631ce1 100644 --- a/request-management-api/request_api/resources/foiworkflow.py +++ b/request-management-api/request_api/resources/foiworkflow.py @@ -46,7 +46,7 @@ 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 + return {'status': 500, 'message': str(err)}, 500 except KeyError as error: return {'status': False, 'message': str(type(error).__name__)}, 400 except BusinessException as exception: 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): From 91cea4b89f972fe724fb96e37d7dcab8a2c8b06d Mon Sep 17 00:00:00 2001 From: Aman-Hundal Date: Wed, 18 Oct 2023 16:22:34 -0700 Subject: [PATCH 5/5] Revised exception handling after comments/discussion with Nick Kan --- .../request_api/resources/foiadmin.py | 9 ++++---- .../request_api/resources/foicfrfee.py | 15 ++++++------ .../request_api/resources/foicomment.py | 11 +++++---- .../request_api/resources/foidocument.py | 15 ++++++------ .../request_api/resources/foiemail.py | 5 ++-- .../request_api/resources/foiextension.py | 13 ++++++----- .../request_api/resources/foinotification.py | 9 ++++---- .../request_api/resources/foipayment.py | 7 +++--- .../request_api/resources/foirecord.py | 23 ++++++++++--------- .../request_api/resources/foirequest.py | 11 +++++---- .../request_api/resources/foiwatcher.py | 13 ++++++----- .../request_api/resources/foiworkflow.py | 3 ++- .../request_api/services/rawrequestservice.py | 2 +- .../request_api/services/workflowservice.py | 2 +- request-management-api/request_api/tracer.py | 2 +- 15 files changed, 76 insertions(+), 64 deletions(-) diff --git a/request-management-api/request_api/resources/foiadmin.py b/request-management-api/request_api/resources/foiadmin.py index 98fff07f2..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 """ @@ -51,7 +52,7 @@ def get(): result = programareadivisionservice().getallprogramareadivisions() return json.dumps(result), 200 except KeyError as error: - return {'status': False, 'message': str(type(error).__name__)}, 400 + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -74,7 +75,7 @@ def post(): # asyncio.ensure_future(); return {'status': result.success, 'message':result.message, 'id':result.identifier}, 200 except KeyError as error: - return {'status': False, 'message': str(type(error).__name__)}, 400 + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -98,7 +99,7 @@ def put(divisionid): # asyncio.ensure_future(); return {'status': result.success, 'message':result.message, 'id':result.identifier}, 200 except KeyError as error: - return {'status': False, 'message': str(type(error).__name__)}, 400 + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -119,7 +120,7 @@ def put(divisionid): # asyncio.ensure_future(); return {'status': result.success, 'message':result.message, 'id':result.identifier}, 200 except KeyError as error: - return {'status': False, 'message': str(type(error).__name__)}, 400 + 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 c8e36e801..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/') @@ -58,9 +59,9 @@ def post(requestid, ministryrequestid): except ValidationError as verr: logging.error(verr) return {'status': False, 'message': str(verr)}, 400 - except KeyError as err: - logging.error(str(type(err).__name__)) - return {'status': False, 'message': EXCEPTION_MESSAGE_BAD_REQUEST}, 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 @@ -88,9 +89,9 @@ def post(requestid, ministryrequestid): except ValidationError as verr: logging.error(verr) return {'status': False, 'message': str(verr)}, 400 - except KeyError as err: - logging.error(str(type(err).__name__)) - return {'status': False, 'message': EXCEPTION_MESSAGE_BAD_REQUEST}, 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 @@ -110,6 +111,6 @@ def get(requestid): result = {"current": cfrfeeservice().getcfrfee(requestid), "history": cfrfeeservice().getcfrfeehistory(requestid)} return json.dumps(result), 200 except KeyError as error: - return {'status': False, 'message': str(type(error).__name__)}, 400 + 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 31ee32336..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') @@ -55,7 +56,7 @@ def post(): asyncio.ensure_future(eventservice().postcommentevent(result.identifier, "ministryrequest", AuthHelper.getuserid())) return {'status': result.success, 'message':result.message,'id':result.identifier} , 200 except KeyError as error: - return {'status': False, 'message': str(type(error).__name__)}, 400 + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -78,7 +79,7 @@ def post(): asyncio.ensure_future(eventservice().postcommentevent(result.identifier, "rawrequest", AuthHelper.getuserid())) return {'status': result.success, 'message':result.message,'id':result.identifier} , 200 except KeyError as error: - return {'status': False, 'message': str(type(error).__name__)}, 400 + 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(requesttype, requestid): else: return {'status': 401, 'message':'Restricted Request'} , 401 except KeyError as error: - return {'status': False, 'message': str(type(error).__name__)}, 400 + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -137,7 +138,7 @@ def put(requesttype, commentid): 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 error: - return {'status': False, 'message': str(type(error).__name__)}, 400 + 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 put(requesttype, commentid): 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 error: - return {'status': False, 'message': str(type(error).__name__)}, 400 + 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/foidocument.py b/request-management-api/request_api/resources/foidocument.py index decf80ddb..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') @@ -50,7 +51,7 @@ def get(requestid, requesttype): result = documentservice().getrequestdocumentsbyrole(requestid, requesttype, AuthHelper.isministrymember()) return json.dumps(result), 200 except KeyError as error: - return {'status': False, 'message': str(type(error).__name__)}, 400 + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -75,7 +76,7 @@ def post(requestid, requesttype): except ValidationError as err: return {'status': False, 'message': str(err)}, 400 except KeyError as error: - return {'status': False, 'message': str(type(error).__name__)}, 400 + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -99,7 +100,7 @@ def post(requestid, documentid, requesttype): except ValidationError as err: return {'status': False, 'message': str(err)}, 400 except KeyError as error: - return {'status': False, 'message': str(type(error).__name__)}, 400 + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -137,7 +138,7 @@ def post(requesttype, requestid, documentid): except ValidationError as err: return {'status': False, 'message': str(err)}, 400 except KeyError as error: - return {'status': False, 'message': str(type(error).__name__)}, 400 + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -160,7 +161,7 @@ def post(requestid, documentid, requesttype): except ValidationError as err: return {'status': False, 'message': str(err)}, 400 except KeyError as error: - return {'status': False, 'message': str(type(error).__name__)}, 400 + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -180,6 +181,6 @@ def post(requestid, documentid, requesttype): result = documentservice().deleterequestdocument(requestid, documentid, AuthHelper.getuserid(), requesttype) return {'status': result.success, 'message':result.message,'id':result.identifier} , 200 except KeyError as error: - return {'status': False, 'message': str(type(error).__name__)}, 400 + 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 143b280b1..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//') @@ -52,7 +53,7 @@ def post(requestid, ministryrequestid, servicename): except ValueError as err: return {'status': 500, 'message': str(err)}, 500 except KeyError as error: - return {'status': False, 'message': str(type(error).__name__)}, 400 + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -73,7 +74,7 @@ def post(requestid, ministryrequestid, servicename): except ValueError as err: return {'status': 500, 'message': str(err)}, 500 except KeyError as error: - return {'status': False, 'message': str(type(error).__name__)}, 400 + 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 b985cc477..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/') @@ -53,7 +54,7 @@ def get(requestid): extensionrecords = extensionservice().getrequestextensions(requestid) return json.dumps(extensionrecords), 200 except KeyError as error: - return {'status': False, 'message': str(type(error).__name__)}, 400 + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -72,7 +73,7 @@ def get(extensionid): extensionrecord = extensionservice().getrequestextension(extensionid) return json.dumps(extensionrecord), 200 except KeyError as error: - return {'status': False, 'message': str(type(error).__name__)}, 400 + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -97,7 +98,7 @@ def post(requestid, ministryrequestid): newduedate, = result.args return {'status': result.success, 'message':result.message,'id':result.identifier, 'newduedate': newduedate or None} , 200 except KeyError as error: - return {'status': False, 'message': str(type(error).__name__)}, 400 + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -122,7 +123,7 @@ def post(ministryrequestid): eventservice().posteventforaxisextension(ministryrequestid, result.args[0], AuthHelper.getuserid(), AuthHelper.getusername(), "add") return {'status': result.success, 'message':result.message} , 200 except KeyError as error: - return {'status': False, 'message': str(type(error).__name__)}, 400 + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -146,7 +147,7 @@ def post(requestid, ministryrequestid, extensionid): 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 error: - return {'status': False, 'message': str(type(error).__name__)}, 400 + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -168,6 +169,6 @@ def post(requestid, ministryrequestid, extensionid): 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 error: - return {'status': False, 'message': str(type(error).__name__)}, 400 + 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 4967f31ab..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') @@ -48,7 +49,7 @@ def get(): except ValueError: return {'status': 500, 'message':"Invalid Request Id"}, 500 except KeyError as error: - return {'status': False, 'message': str(type(error).__name__)}, 400 + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -73,7 +74,7 @@ def delete(type=None,idnumber=None,notficationid=None): except ValueError: return {'status': 500, 'message':"Invalid Request Id"}, 500 except KeyError as error: - return {'status': False, 'message': str(type(error).__name__)}, 400 + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -93,7 +94,7 @@ def post(): respcode = 200 if reminderresponse.success == True else 500 return {'status': reminderresponse.success, 'message':reminderresponse.message,'id': reminderresponse.identifier} , respcode except KeyError as error: - return {'status': False, 'message': str(type(error).__name__)}, 400 + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -114,6 +115,6 @@ def post(request_id: int, ministry_request_id: int): respcode = 200 if reminderresponse.success == True else 500 return {'status': reminderresponse.success, 'message':reminderresponse.message,'id': reminderresponse.identifier} , respcode except KeyError as error: - return {'status': False, 'message': str(type(error).__name__)}, 400 + 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 b637d0772..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/') @@ -49,7 +50,7 @@ def post(requestid, ministryrequestid): result = paymentservice().createpayment(requestid, ministryrequestid, paymentschema) return {'status': result.success, 'message':result.message,'id':result.identifier} , 200 except KeyError as error: - return {'status': False, 'message': str(type(error).__name__)}, 400 + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -70,7 +71,7 @@ def post(requestid, ministryrequestid): result = paymentservice().cancelpayment(requestid, ministryrequestid, paymentschema) return {'status': result.success, 'message':result.message,'id':result.identifier} , 200 except KeyError as error: - return {'status': False, 'message': str(type(error).__name__)}, 400 + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -89,7 +90,7 @@ def get(requestid, ministryrequestid): result = paymentservice().getpayment(requestid, ministryrequestid) return json.dumps(result), 200 except KeyError as error: - return {'status': False, 'message': str(type(error).__name__)}, 400 + 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 e90e9ae34..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/') @@ -47,7 +48,7 @@ def get(requestid, ministryrequestid): result = recordservice().fetch(requestid, ministryrequestid) return json.dumps(result), 200 except KeyError as error: - return {'status': False, 'message': str(type(error).__name__)}, 400 + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except Exception as exception: return {'status': False, 'message': str(exception)}, 500 @@ -70,7 +71,7 @@ def post(requestid, ministryrequestid): respcode = 200 if response.success == True else 500 return {'status': response.success, 'message':response.message,'data': response.args[0]} , respcode except KeyError as error: - return {'status': False, 'message': str(type(error).__name__)}, 400 + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -92,7 +93,7 @@ def post(requestid, ministryrequestid): result = recordservice().update(requestid, ministryrequestid, data, AuthHelper.getuserid()) return {'status': result.success, 'message':result.message,'id':result.identifier} , 200 except KeyError as error: - return {'status': False, 'message': str(type(error).__name__)}, 400 + 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(requestid, ministryrequestid): result = recordservice().retry(requestid, ministryrequestid, recordschema) return {'status': result.success, 'message':result.message,'id':result.identifier} , 200 except KeyError as error: - return {'status': False, 'message': str(type(error).__name__)}, 400 + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -135,7 +136,7 @@ def post(requestid, ministryrequestid,recordid): return {'status': result.success, 'message':result.message,'id':result.identifier} , 200 except KeyError as error: - return {'status': False, 'message': str(type(error).__name__)}, 400 + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -158,7 +159,7 @@ def post(requestid, ministryrequestid, recordstype): respcode = 200 if response.success == True else 500 return {'status': response.success, 'message':response.message,'id':response.identifier}, respcode except KeyError as error: - return {'status': False, 'message': str(type(error).__name__)}, 400 + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -178,7 +179,7 @@ def get(requestid, ministryrequestid, recordstype): result = recordservice().getpdfstitchpackagetodownload(ministryrequestid, recordstype.lower()) return json.dumps(result), 200 except KeyError as error: - return {'status': False, 'message': str(type(error).__name__)}, 400 + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -199,8 +200,8 @@ def get(requestid, ministryrequestid, recordstype): #("getpdfstichstatus result == ", result) return result, 200 except KeyError as error: - print(str(type(error).__name__)) - return {'status': False, 'message': str(type(error).__name__)}, 400 + 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 @@ -225,8 +226,8 @@ def get(requestid, ministryrequestid, recordstype): #print("records changed == ", result) return result, 200 except KeyError as error: - print(str(type(error).__name__)) - return {'status': False, 'message': str(type(error).__name__)}, 400 + 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 diff --git a/request-management-api/request_api/resources/foirequest.py b/request-management-api/request_api/resources/foirequest.py index 037e89a55..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') @@ -73,7 +74,7 @@ def get(foirequestid,foiministryrequestid,usertype = None): except ValueError: return {'status': 500, 'message':"Invalid Request Id"}, 500 except KeyError as error: - return {'status': False, 'message': str(type(error).__name__)}, 400 + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -119,7 +120,7 @@ def post(): except ValidationError as err: return {'status': False, 'message': str(err)}, 400 except KeyError as error: - return {'status': False, 'message': str(type(error).__name__)}, 400 + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -148,7 +149,7 @@ def post(foirequestid,foiministryrequestid): except ValidationError as err: return {'status': False, 'message': str(err)}, 400 except KeyError as error: - return {'status': False, 'message': str(type(error).__name__)}, 400 + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -188,7 +189,7 @@ def post(foirequestid,foiministryrequestid,actiontype = None,usertype = None): except ValidationError as err: return {'status': False, 'message': str(err)}, 400 except KeyError as error: - return {'status': False, 'message': str(type(error).__name__)}, 400 + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -247,7 +248,7 @@ def get(foirequestid, foiministryrequestid): except ValueError: return {'status': 500, 'message':"Invalid Request Id"}, 500 except KeyError as error: - return {'status': False, 'message': str(type(error).__name__)}, 400 + 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/foiwatcher.py b/request-management-api/request_api/resources/foiwatcher.py index 065ba1154..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/') @@ -50,7 +51,7 @@ def get(requestid): except ValueError as err: return {'status': 500, 'message': str(err)}, 500 except KeyError as error: - return {'status': False, 'message': str(type(error).__name__)}, 400 + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -73,7 +74,7 @@ def post(): eventservice().posteventforwatcher(requestjson["requestid"], requestjson, "rawrequest",AuthHelper.getuserid(), AuthHelper.getusername()) return {'status': result.success, 'message':result.message} , 200 except KeyError as error: - return {'status': False, 'message': str(type(error).__name__)}, 400 + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -92,7 +93,7 @@ def put(requestid): result = watcherservice().disablerawrequestwatchers(requestid, AuthHelper.getuserid()) return {'status': result.success, 'message':result.message,'id':result.identifier} , 200 except KeyError as error: - return {'status': False, 'message': str(type(error).__name__)}, 400 + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -111,7 +112,7 @@ def get(ministryrequestid): result = watcherservice().getministryrequestwatchers(ministryrequestid,AuthHelper.isministrymember()) return json.dumps(result), 200 except KeyError as error: - return {'status': False, 'message': str(type(error).__name__)}, 400 + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -134,7 +135,7 @@ def post(): eventservice().posteventforwatcher(requestjson["ministryrequestid"], requestjson, "ministryrequest", AuthHelper.getuserid(), AuthHelper.getusername()) return {'status': result.success, 'message':result.message} , 200 except KeyError as error: - return {'status': False, 'message': str(type(error).__name__)}, 400 + return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400 except BusinessException as exception: return {'status': exception.status_code, 'message':exception.message}, 500 @@ -153,6 +154,6 @@ def put(ministryrequestid): result = watcherservice().disableministryrequestwatchers(ministryrequestid, AuthHelper.getuserid()) return {'status': result.success, 'message':result.message,'id':result.identifier} , 200 except KeyError as error: - return {'status': False, 'message': str(type(error).__name__)}, 400 + 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 e22631ce1..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') @@ -48,7 +49,7 @@ def post(requesttype, requestid): except ValueError as err: return {'status': 500, 'message': str(err)}, 500 except KeyError as error: - return {'status': False, 'message': str(type(error).__name__)}, 400 + 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 c72d3ccf1..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") + 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 e3faaf143..f4b6f81a0 100644 --- a/request-management-api/request_api/services/workflowservice.py +++ b/request-management-api/request_api/services/workflowservice.py @@ -26,7 +26,7 @@ class workflowservice: def createinstance(self, definitionkey, message): response = bpmservice().createinstance(definitionkey, json.loads(message)) if response is None: - raise BusinessException(Error.INVALID_INPUT) + 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)