From 4f3ec03fd6aee53aabcd2fed1df065517852208b Mon Sep 17 00:00:00 2001 From: Mangesh-Khairnar Date: Thu, 15 Oct 2020 19:01:40 +0530 Subject: [PATCH] fix: follow single responsibility principle --- .../integration_request/integration_request.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/frappe/integrations/doctype/integration_request/integration_request.py b/frappe/integrations/doctype/integration_request/integration_request.py index 7668ce683a..f1d59beb5a 100644 --- a/frappe/integrations/doctype/integration_request/integration_request.py +++ b/frappe/integrations/doctype/integration_request/integration_request.py @@ -23,19 +23,16 @@ class IntegrationRequest(Document): self.save(ignore_permissions=True) frappe.db.commit() - def handle_sucess(self, response): + def handle_success(self, response): """update the output field with the response along with the relevant status""" - self.process_response("output", response) + if isinstance(response, string_types): + response = json.loads(response) + self.db_set("status", "Completed") + self.db_set("output", json.dumps(response, default=json_handler)) def handle_failure(self, response): """update the error field with the response along with the relevant status""" - self.process_response("error", response) - - def process_response(self, ref_field, response): - """Update the response in integration request with status based on reference""" if isinstance(response, string_types): response = json.loads(response) - - status = "Completed" if ref_field == "output" else "Failed" - self.db_set(ref_field, json.dumps(response, default=json_handler)) - self.db_set("status", status) \ No newline at end of file + self.db_set("status", "Failed") + self.db_set("error", json.dumps(response, default=json_handler)) \ No newline at end of file