I\'m coding REST Api-s in spring boot. I want to make sure that my code is readable to front-end developers using swagger API development tool (Swagger). For example
I would recommend to do it like this .
@GetMapping("/getOne")
public Response getOne(@RequestParam String id) {
ResponseEntity resbranch;
ResponseEntity reserror;
try {
resbranch=new ResponseEntity(branchService.getOne(id), HttpStatus.OK);
return Response.status(200).entity(resbranch).build();
} catch (Exception e) {
reserror=new ResponseEntity(new FindError(e.getMessage()), HttpStatus.BAD_REQUEST);
return Response.status(400).entity(reserror).build();
}
}
200 is for OK and 400 is for bad request. Here there wont be anymore ambiguous types..