Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into feat/CIV-15686
Browse files Browse the repository at this point in the history
  • Loading branch information
Gareth40342 committed Jan 15, 2025
2 parents 6618d7c + 7289ed4 commit a5b398f
Show file tree
Hide file tree
Showing 81 changed files with 2,136 additions and 2,042 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,8 @@ sonarqube {
property "sonar.coverage.exclusions", "**/model/**, **/config/**/*Configuration.java, **/request/servlet/** , **/controllers/**, **/testingsupport/**, **/*ExternalTaskListener.java, **/*BaseExternalTaskHandler.java, **/stereotypes/**, **/*Exception.java, **/EventHistoryMapper*.java, **/model/hearingvalues/**, **/enums/hearing/**, **/fees/client/**, **/enums/sdo/**, **/service/PaymentsService.java, **/DashboardWithParamsCallbackHandler.java, **/PaymentRequestUpdateCallbackService.java, **/advice/**"
property "sonar.cpd.exclusions", "**/*DocumentManagementService.java, **/*Spec*.java, **/*CcdDashboardClaimantClaimMatcher.java, **/*CcdDashboardDefendantClaimMatcher.java"
property "sonar.exclusions", "**/hmc/model/**, **/model/hearingvalues/**, **/handler/callback/camunda/dashboardnotifications/claimant/CCJRequestedDashboardNotificationHandler.java, **/handler/callback/camunda/dashboardnotifications/claimant/ClaimantCCJResponseNotificationHandler.java" +
", **/handler/callback/camunda/dashboardnotifications/claimant/ClaimantResponseNotificationHandler.java, **/utils/HmcDataUtils.java, **/handler/callback/camunda/dashboardnotifications/defendant/MoreTimeRequestedDashboardNotificationDefendantHandler.java, **/handler/callback/camunda/dashboardnotifications/claimant/ClaimantMediationSuccessfulDashboardNotificationHandler.java, **/handler/callback/camunda/dashboardnotifications/claimant/ClaimSettledDashboardNotificationHandler.java, **/handler/callback/camunda/dashboardnotifications/claimant/HearingScheduledClaimantNotificationHandler.java, **/handler/callback/camunda/dashboardnotifications/defendant/SettleClaimPaidInFullDefendantDashboardNotificationHandler.java, **/handler/callback/camunda/dashboardnotifications/defendant/DefendantNotifyDiscontinuanceDashboardNotificationHandler.java" +
",**/utils/CaseQueriesUtuil.java, **/handler/callback/user/RaiseQueryCallbackHandler.java, **/handler/callback/user/RespondQueryCallbackHandler.java, **/utils/CaseQueriesInitializer.java"
", **/handler/callback/camunda/dashboardnotifications/claimant/ClaimantResponseNotificationHandler.java, **/utils/**, **/filters/**, **/handler/callback/camunda/dashboardnotifications/defendant/MoreTimeRequestedDashboardNotificationDefendantHandler.java, **/handler/callback/camunda/dashboardnotifications/claimant/ClaimantMediationSuccessfulDashboardNotificationHandler.java, **/handler/callback/camunda/dashboardnotifications/claimant/ClaimSettledDashboardNotificationHandler.java, **/handler/callback/camunda/dashboardnotifications/claimant/HearingScheduledClaimantNotificationHandler.java, **/handler/callback/camunda/dashboardnotifications/defendant/SettleClaimPaidInFullDefendantDashboardNotificationHandler.java, **/handler/callback/camunda/dashboardnotifications/defendant/DefendantNotifyDiscontinuanceDashboardNotificationHandler.java" +
",**/utils/CaseQueriesUtil.java, **/handler/callback/user/RaiseQueryCallbackHandler.java, **/handler/callback/user/RespondQueryCallbackHandler.java"
property "sonar.host.url", "https://sonar.reform.hmcts.net/"
property "sonar.web.javaOpts", "-Xmx2G"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,85 +9,131 @@
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.multipart.MaxUploadSizeExceededException;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
import org.springframework.web.util.ContentCachingRequestWrapper;
import uk.gov.hmcts.reform.civil.documentmanagement.DocumentUploadException;
import uk.gov.hmcts.reform.civil.exceptions.CaseDataInvalidException;
import uk.gov.hmcts.reform.civil.exceptions.CaseNotFoundException;
import uk.gov.hmcts.reform.civil.exceptions.IncludesLitigantInPersonException;
import uk.gov.hmcts.reform.civil.exceptions.MissingFieldsUpdatedException;
import uk.gov.hmcts.reform.civil.exceptions.UserNotFoundOnCaseException;
import uk.gov.hmcts.reform.civil.request.RequestData;
import uk.gov.hmcts.reform.civil.service.pininpost.exception.PinNotMatchException;
import uk.gov.hmcts.reform.civil.service.search.exceptions.SearchServiceCaseNotFoundException;

import static uk.gov.hmcts.reform.civil.utils.ContentCachingRequestWrapperUtil.getCaseId;
import static uk.gov.hmcts.reform.civil.utils.ContentCachingRequestWrapperUtil.getUserId;

@Slf4j
@ControllerAdvice
@RequiredArgsConstructor
public class ControllerExceptionHandler extends ResponseEntityExceptionHandler {

private final RequestData requestData;

@ExceptionHandler(CaseNotFoundException.class)
public ResponseEntity<Object> caseNotFoundBadRequest(CaseNotFoundException caseNotFoundException) {
public ResponseEntity<Object> caseNotFoundBadRequest(CaseNotFoundException caseNotFoundException,
ContentCachingRequestWrapper contentCachingRequestWrapper) {
String errorMessage = "Case not found with message: %s for case %s run by user %s";
log.error(errorMessage
.formatted(caseNotFoundException.getMessage(), requestData.caseId(), requestData.userId())
.formatted(caseNotFoundException.getMessage(), getCaseId(contentCachingRequestWrapper),
getUserId(contentCachingRequestWrapper)
)
);
return new ResponseEntity<>("Case was not found", new HttpHeaders(), HttpStatus.BAD_REQUEST);
}

@ExceptionHandler(SearchServiceCaseNotFoundException.class)
public ResponseEntity<Object> caseNotFoundUnauthorised(SearchServiceCaseNotFoundException searchServiceCaseNotFoundException) {
public ResponseEntity<Object> caseNotFoundUnauthorised(SearchServiceCaseNotFoundException searchServiceCaseNotFoundException,
ContentCachingRequestWrapper contentCachingRequestWrapper) {
String errorMessage = "Search service case not found with message: %s for case %s run by user %s";
log.error(errorMessage.formatted(searchServiceCaseNotFoundException.getMessage(), requestData.caseId(), requestData.userId()));
log.error(errorMessage.formatted(
searchServiceCaseNotFoundException.getMessage(),
getCaseId(contentCachingRequestWrapper),
getUserId(contentCachingRequestWrapper)
));
return new ResponseEntity<>("UNAUTHORIZED", new HttpHeaders(), HttpStatus.UNAUTHORIZED);
}

@ExceptionHandler(PinNotMatchException.class)
public ResponseEntity<Object> pinNotMatchedUnauthorised(PinNotMatchException pinNotMatchException) {
public ResponseEntity<Object> pinNotMatchedUnauthorised(PinNotMatchException pinNotMatchException,
ContentCachingRequestWrapper contentCachingRequestWrapper) {
String errorMessage = "Pin not matched unauthorized error with message: %s for case %s run by user %s";
log.error(errorMessage.formatted(pinNotMatchException.getMessage(), requestData.caseId(), requestData.userId()));
log.error(errorMessage.formatted(pinNotMatchException.getMessage(), getCaseId(contentCachingRequestWrapper),
getUserId(contentCachingRequestWrapper)
));
return new ResponseEntity<>("BAD_REQUEST", new HttpHeaders(), HttpStatus.BAD_REQUEST);
}

@ExceptionHandler(DocumentUploadException.class)
public ResponseEntity<Object> documentUploadException(DocumentUploadException documentUploadException) {
public ResponseEntity<Object> documentUploadException(DocumentUploadException documentUploadException,
ContentCachingRequestWrapper contentCachingRequestWrapper) {
String errorMessage = "Document upload error with message: %s for case %s run by user %s";
log.error(errorMessage.formatted(documentUploadException.getMessage(), requestData.caseId(), requestData.userId()));
log.error(errorMessage.formatted(documentUploadException.getMessage(), getCaseId(contentCachingRequestWrapper),
getUserId(contentCachingRequestWrapper)
));
return new ResponseEntity<>("Document upload unsuccessful", new HttpHeaders(), HttpStatus.BAD_REQUEST);
}

@ExceptionHandler(MaxUploadSizeExceededException.class)
public ResponseEntity<Object> documentUploadException(MaxUploadSizeExceededException maxUploadSizeExceededException) {
public ResponseEntity<Object> documentUploadException(MaxUploadSizeExceededException maxUploadSizeExceededException,
ContentCachingRequestWrapper contentCachingRequestWrapper) {
String errorMessage = "Max upload size exceeded error with message: %s for case %s run by user %s";
log.error(errorMessage.formatted(maxUploadSizeExceededException.getMessage(), requestData.caseId(), requestData.userId()));
log.error(errorMessage.formatted(
maxUploadSizeExceededException.getMessage(),
getCaseId(contentCachingRequestWrapper),
getUserId(contentCachingRequestWrapper)
));
return new ResponseEntity<>("Document upload unsuccessful", new HttpHeaders(), HttpStatus.BAD_REQUEST);
}

@ExceptionHandler(MissingFieldsUpdatedException.class)
public ResponseEntity<Object> partyIdsUpdatedException(MissingFieldsUpdatedException missingFieldsUpdatedException) {
public ResponseEntity<Object> partyIdsUpdatedException(MissingFieldsUpdatedException missingFieldsUpdatedException,
ContentCachingRequestWrapper contentCachingRequestWrapper) {
String errorMessage = "Error when attempting to update missing hearing values fields with message: %s for case %s run by user %s";
log.error(errorMessage.formatted(missingFieldsUpdatedException.getMessage(), requestData.caseId(), requestData.userId()));
log.error(errorMessage.formatted(
missingFieldsUpdatedException.getMessage(),
getCaseId(contentCachingRequestWrapper),
getUserId(contentCachingRequestWrapper)
));
return new ResponseEntity<>("Missing fields updated", new HttpHeaders(), HttpStatus.NOT_FOUND);
}

@ExceptionHandler(CaseDataInvalidException.class)
public ResponseEntity<Object> caseDataInvalidException(CaseDataInvalidException caseDataInvalidException) {
public ResponseEntity<Object> caseDataInvalidException(CaseDataInvalidException caseDataInvalidException,
ContentCachingRequestWrapper contentCachingRequestWrapper) {
String errorMessage = "Case data is invalid error with message: %s for case %s run by user %s";
log.error(errorMessage.formatted(caseDataInvalidException.getMessage(), requestData.caseId(), requestData.userId()));
return new ResponseEntity<>("Submit claim unsuccessful, Invalid Case data", new HttpHeaders(), HttpStatus.UNPROCESSABLE_ENTITY);
log.error(errorMessage.formatted(caseDataInvalidException.getMessage(), getCaseId(contentCachingRequestWrapper),
getUserId(contentCachingRequestWrapper)
));
return new ResponseEntity<>(
"Submit claim unsuccessful, Invalid Case data",
new HttpHeaders(),
HttpStatus.UNPROCESSABLE_ENTITY
);
}

@ExceptionHandler(UserNotFoundOnCaseException.class)
public ResponseEntity<Object> userNotFoundOnCaseException(UserNotFoundOnCaseException userNotFoundOnCaseException) {
public ResponseEntity<Object> userNotFoundOnCaseException(UserNotFoundOnCaseException userNotFoundOnCaseException,
ContentCachingRequestWrapper contentCachingRequestWrapper) {
String errorMessage = "User not found error with message: %s for case %s run by user %s";
log.error(errorMessage.formatted(userNotFoundOnCaseException.getMessage(), requestData.caseId(), requestData.userId()));
log.error(errorMessage.formatted(
userNotFoundOnCaseException.getMessage(),
getCaseId(contentCachingRequestWrapper),
getUserId(contentCachingRequestWrapper)
));
return new ResponseEntity<>(userNotFoundOnCaseException.getMessage(), new HttpHeaders(), HttpStatus.NOT_FOUND);
}

@ExceptionHandler(IncludesLitigantInPersonException.class)
public ResponseEntity<Object> litigantInPersonException(IncludesLitigantInPersonException includesLitigantInPersonException) {
public ResponseEntity<Object> litigantInPersonException(IncludesLitigantInPersonException includesLitigantInPersonException,
ContentCachingRequestWrapper contentCachingRequestWrapper) {
String errorMessage = "Action not accepted on case with message: %s for case %s run by user %s";
log.error(errorMessage.formatted(includesLitigantInPersonException.getMessage(), requestData.caseId(), requestData.userId()));
return new ResponseEntity<>(includesLitigantInPersonException.getMessage(), new HttpHeaders(), HttpStatus.INTERNAL_SERVER_ERROR);
log.error(errorMessage.formatted(
includesLitigantInPersonException.getMessage(),
getCaseId(contentCachingRequestWrapper),
getUserId(contentCachingRequestWrapper)
));
return new ResponseEntity<>(
includesLitigantInPersonException.getMessage(),
new HttpHeaders(),
HttpStatus.INTERNAL_SERVER_ERROR
);
}
}
Loading

0 comments on commit a5b398f

Please sign in to comment.