Commit 56411dfc by neel

Hnadling try catch with Error code and message

parent 7d475aea
...@@ -74,13 +74,20 @@ public class LeaderCalc { ...@@ -74,13 +74,20 @@ public class LeaderCalc {
}catch(ResourceNotFoundException e) { }catch(ResourceNotFoundException e) {
calc = new JSONObject();
calc.put("Error_Code", "500");
calc.put("Error_Message", "Technical Error caught while calculating");
System.out.println(e); System.out.println(e);
e.printStackTrace(); e.printStackTrace();
return new ResponseEntity(new ApiResponse(StatusCode.RESOURCE_NOT_FOUND, true, "calculation failed", null), HttpStatus.NOT_FOUND); return new ResponseEntity(new ApiResponse(StatusCode.RESOURCE_NOT_FOUND, true, "calculation failed", calc), HttpStatus.NOT_FOUND);
}catch(Exception e) { }catch(Exception e) {
calc = new JSONObject();
calc.put("Error_Code", "500");
calc.put("Error_Message", "Technical Error caught while calculating");
e.printStackTrace(); e.printStackTrace();
System.out.println(e); System.out.println(e);
return new ResponseEntity(new ApiResponse(StatusCode.UNEXPECTED_ERROR, true, "calculation failed", null), HttpStatus.BAD_REQUEST); return new ResponseEntity(new ApiResponse(StatusCode.UNEXPECTED_ERROR, true, "calculation failed", calc), HttpStatus.BAD_REQUEST);
} }
return new ResponseEntity(new ApiResponse(HttpStatus.OK.value(), true, "calculation done successfully", calc.toString()), HttpStatus.OK); return new ResponseEntity(new ApiResponse(HttpStatus.OK.value(), true, "calculation done successfully", calc.toString()), HttpStatus.OK);
......
...@@ -26,7 +26,7 @@ public class LeaderCalcServiceImpl implements LeaderCalcService { ...@@ -26,7 +26,7 @@ public class LeaderCalcServiceImpl implements LeaderCalcService {
public JSONObject calculate(String data) { public JSONObject calculate(String data) {
JSONObject Calc_JSON = null; JSONObject Calc_JSON = null;
try {
JSONObject InputData = new JSONObject(data); JSONObject InputData = new JSONObject(data);
Calc_JSON = InputData.getJSONObject("CALC_JSON"); Calc_JSON = InputData.getJSONObject("CALC_JSON");
...@@ -525,16 +525,10 @@ public class LeaderCalcServiceImpl implements LeaderCalcService { ...@@ -525,16 +525,10 @@ public class LeaderCalcServiceImpl implements LeaderCalcService {
System.out.println(Calc_JSON); System.out.println(Calc_JSON);
return Calc_JSON; return Calc_JSON;
}
catch (Exception e) {
Calc_JSON = new JSONObject();
Calc_JSON.put("Error_Code", "500");
Calc_JSON.put("Error_Message", "Technical Error caught while calculating");
return Calc_JSON;
}
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment