In my core controller method, I’m sending a ResponseEntity with status 500
CORE CONTROLLER
@PostMapping("/getGroupDefinitions")
public ResponseEntity<ResponseDTO> getGroupDefinition(@RequestBody GetGroupDefinitionRequestDao getGroupDefinitionRequestDao) {
String endPoint = "/getGroupDefinitions";
Timestamp landingTime = Timestamp.valueOf(LocalDateTime.now());
log.info("getGroupDefinitionRequestDao: {}", getGroupDefinitionRequestDao.toString());
try {
List<PimGroupDefinitionProjection> response = pimGroupDefinitionService.getGroupDefinitions(getGroupDefinitionRequestDao);
return ResponseUtil.sendResponse(
response,
landingTime,
HttpStatus.OK,
200,
RequestMethod.POST.name(),
endPoint
);
} catch (Exception e) {
log.error("Error while getting Group Definitions: {}", (Object) e.getStackTrace());
ResponseEntity<ResponseDTO> errorResponse = ResponseUtil.sendErrorResponse(
"GET_GROUP_DEFINITIONS_ERROR",
"Error while getting group definitions, " + e.getMessage(),
landingTime,
HttpStatus.INTERNAL_SERVER_ERROR,
500
);
log.error("Error while getting Group Definitions: {}", errorResponse);
return errorResponse;
}
}
BFF CONTROLLER
@ActivityLogging
@PostMapping("/getGroupDefinitions")
public ResponseEntity<ResponseDTO> getGroupDefinitions(@RequestBody GetGroupDefinitionsRequestDao getGroupDefinitionsRequestDao, HttpServletRequest request) {
String endPoint = "/getGroupDefinitions";
log.info(endPoint + "request {}", getGroupDefinitionsRequestDao);
Timestamp landingTime = Timestamp.valueOf(LocalDateTime.now());
try {
getGroupDefinitionsCoreResponse = pimCoreClient.getGroupDefinitions(getGroupDefinitionsRequestDao);
if (getGroupDefinitionsCoreResponse.getStatusCode() != HttpStatus.OK) {
throw new Exception(Objects.requireNonNull(getGroupDefinitionsCoreResponse.getBody()).getResponseMessage().getMessage());
}
return ResponseUtil.sendResponse(
Objects.requireNonNull(getGroupDefinitionsCoreResponse.getBody()).getResponseData(),
landingTime,
HttpStatus.OK,
200,
"POST",
endPoint
);
} catch (UnauthorizedException e) {
log.error(LocalExceptionMessage.MSG_UNAUTHORIZED_EX + LocalExceptionMessage.MSG_MESSAGE + e.getMessage());
return ResponseUtil.sendErrorResponse(
"U",
e.getMessage(),
landingTime,
HttpStatus.UNAUTHORIZED,
401
);
} catch (Exception e) {
log.error(LocalExceptionMessage.MSG_EX_FOUND + LocalExceptionMessage.MSG_MESSAGE + e.getMessage());
return ResponseUtil.sendErrorResponse(
"INTERNAL_SERVER_ERROR",
e.getMessage(),
landingTime,
HttpStatus.INTERNAL_SERVER_ERROR,
500
);
}
}
}
So in my bff controller, will the status of the coreResponse be checked in the if statement or it will run into the catch block?
When i debug it, after the pimGroupDefinitionService.getGroupDefinitions(getGroupDefinitionRequestDao) is called it is running into catch statement
I want to understand how a ResponseEntity with status 500 will be handled.
I’m using feign for microservice communication between bff and core
2