Reputation: 2041
I am making app with Rest Services and i want to handle the exceptions and status code.
When i send the correct parametars to Postman i get the response and the status code is 202 OK so that is good.
When i send the first parameter correct and for seccond i send some chars i get status code 400 Bad Request and some message so that is good too.
But, when i send the first parameter correct and in the seccond i delete one number i am getting Status: 404 Not Found (Which is correct) and blank page in Postman without some message.
So my question is:
Is that alright to get only status code 404 and blank page or i need to change something in the code to get the message too.
My second question is about Internal Server Error 500. How can i implement it and how to test it?
@CrossOrigin
@RequestMapping(value = "/blaa/{startDate}/{endDate}", method = RequestMethod.GET)
public ResponseEntity<List<Nodes>> listsOfbla(@PathVariable Long startDate,
@PathVariable Long endDate) {
startEndDateRequestTotal.inc();
List<Nodes> listOfbla= NodesService.getFromToData(startDate, endDate);
LOG.info("GET Request was made with two paramaters ", startDate, endDate);
for (int i = 0; i < listOfbla (); i++) {
if (listOfbla(i).getStampm().equals(startDate)) {
for (int j = 0; j < listOfbla (); j++) {
if (listOfbla(j).getStampm().equals(endDate)) {
return new ResponseEntity<List<Nodes>>listOfbla HttpStatus.OK);
}
}
} else {
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
}
if (listOfbla.isEmpty()) {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
LOG.info("Retruning Nodes objects from specified date");
return new ResponseEntity<List<Nodes>>(listOfbla, HttpStatus.OK);
}
Upvotes: 1
Views: 722
Reputation: 1583
For your first question: That is enough you receive the status code and you can make for example. If status code = 404 send me this message.
Upvotes: 1