import org.aspectj.lang.annotation.Aspect;
import org.onap.policy.models.base.PfModelRuntimeException;
import org.onap.policy.models.errors.concepts.ErrorResponse;
-import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.transaction.TransactionException;
* @param exception the exception
*/
@AfterThrowing(pointcut = "execution(* org.onap.policy.api.main.service.*.*(..))", throwing = "exception")
- public ResponseEntity<Object> handleServiceException(JoinPoint joinPoint, RuntimeException exception) {
+ public void handleServiceException(JoinPoint joinPoint, RuntimeException exception) {
if (exception instanceof PolicyApiRuntimeException || exception instanceof PfModelRuntimeException) {
throw exception;
} else {
*/
@AfterThrowing(pointcut = "execution(* org.onap.policy.api.main..*.*(..))"
+ " && !execution(* org.onap.policy.api.main.rest.provider.statistics.*.*(..))", throwing = "exception")
- public ResponseEntity<Object> handleTransactionException(JoinPoint joinPoint, TransactionException exception) {
+ public void handleTransactionException(JoinPoint joinPoint, TransactionException exception) {
final var errorResponse = new ErrorResponse();
errorResponse.setResponseCode(Response.Status.INTERNAL_SERVER_ERROR);
errorResponse.setErrorMessage(exception.getMessage());
throw new PolicyApiRuntimeException(exception.getMessage(), exception.getCause(), errorResponse, null);
}
-}
\ No newline at end of file
+}
public ResponseEntity<HealthCheckReport> getHealthCheck(\r
@RequestHeader(name = REQUEST_ID_NAME, required = false)\r
@ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {\r
- updateApiStatisticsCounter(Target.OTHER, HttpStatus.OK, HttpMethod.GET);\r
- return makeOkResponse(requestId, healthCheckProvider.performHealthCheck());\r
+ final var report = healthCheckProvider.performHealthCheck();\r
+ updateApiStatisticsCounter(Target.OTHER, HttpStatus.resolve(report.getCode()), HttpMethod.GET);\r
+ return makeResponse(requestId, report, report.getCode());\r
}\r
\r
/**\r
}\r
}\r
}\r
-}
\ No newline at end of file
+}\r
import org.onap.policy.common.utils.coder.StandardCoder;\r
import org.slf4j.Logger;\r
import org.slf4j.LoggerFactory;\r
+import org.springframework.http.HttpStatus;\r
import org.springframework.http.ResponseEntity;\r
import org.springframework.web.bind.annotation.ExceptionHandler;\r
import org.springframework.web.context.request.WebRequest;\r
protected final Coder coder = new StandardCoder();\r
\r
protected <T> ResponseEntity<T> makeOkResponse(UUID requestId, T respEntity) {\r
- return CommonRestController.addLoggingHeaders(addVersionControlHeaders(ResponseEntity.ok()), requestId)\r
+ return makeResponse(requestId, respEntity, HttpStatus.OK.value());\r
+ }\r
+\r
+ protected <T> ResponseEntity<T> makeResponse(UUID requestId, T respEntity, int status) {\r
+ return CommonRestController\r
+ .addLoggingHeaders(addVersionControlHeaders(ResponseEntity.status(status)), requestId)\r
.body(respEntity);\r
}\r
\r
CommonRestController.addVersionControlHeaders(ResponseEntity.status(status)),\r
requestId != null ? UUID.fromString(requestId) : ex.getRequestId()).body(ex.getErrorResponse());\r
}\r
-}
\ No newline at end of file
+}\r
import org.onap.policy.api.main.service.ToscaServiceTemplateService;
import org.onap.policy.common.endpoints.report.HealthCheckReport;
import org.onap.policy.common.utils.network.NetworkUtil;
-import org.onap.policy.models.base.PfModelRuntimeException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
try {
toscaServiceTemplateService.getDefaultJpaToscaServiceTemplate();
return true;
- } catch (PfModelRuntimeException pfme) {
- LOGGER.warn("Api to database connection check failed. Details - ", pfme);
+ } catch (Exception ex) {
+ LOGGER.warn("Api to database connection check failed. Details: ", ex);
return false;
}
}
-}
\ No newline at end of file
+}