Skip to content

Commit

Permalink
Change handling for new notification.
Browse files Browse the repository at this point in the history
Make consistent with existing validation failures.
  • Loading branch information
tom-saunders-cts committed Jan 13, 2025
1 parent d611763 commit 07aa4c3
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package uk.gov.hmcts.probate.exception;

public class RequestInformationParameterException extends RuntimeException {
public class RequestInformationParameterException extends BusinessValidationException {
private static final String INVALID_PERSONALISATION_ERROR_MESSAGE =
"Markdown Link detected in case data, stop sending notification email.";

public RequestInformationParameterException() {
super(INVALID_PERSONALISATION_ERROR_MESSAGE);
super(INVALID_PERSONALISATION_ERROR_MESSAGE, INVALID_PERSONALISATION_ERROR_MESSAGE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import uk.gov.hmcts.probate.exception.ConnectionException;
import uk.gov.hmcts.probate.exception.NotFoundException;
import uk.gov.hmcts.probate.exception.OCRMappingException;
import uk.gov.hmcts.probate.exception.RequestInformationParameterException;
import uk.gov.hmcts.probate.exception.SocketException;
import uk.gov.hmcts.probate.exception.model.ErrorResponse;
import uk.gov.hmcts.probate.model.ccd.ocr.ValidationResponse;
Expand Down Expand Up @@ -92,22 +91,6 @@ public ResponseEntity<ErrorResponse> handle(ConnectionException exception) {
return new ResponseEntity<>(errorResponse, headers, SERVICE_UNAVAILABLE);
}

@ExceptionHandler(value = RequestInformationParameterException.class)
public ResponseEntity<CallbackResponse> handle(RequestInformationParameterException exception) {
log.warn("Invalid parameters when sending email", exception);

final List<String> errors = List.of(exception.getMessage());
final CallbackResponse errorResponse = CallbackResponse.builder()
.errors(errors)
.build();
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);

return ResponseEntity.ok()
.headers(headers)
.body(errorResponse);
}

@ExceptionHandler(value = NotFoundException.class)
public ResponseEntity<ErrorResponse> handle(NotFoundException exception) {
log.warn("Not found exception", exception);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ void shouldReturnOCRMappingException() {
@Test
void shouldReturnMarkdownError() {
RequestInformationParameterException ex = mock(RequestInformationParameterException.class);
when(ex.getMessage()).thenReturn(EXCEPTION_MESSAGE);
when(ex.getMessage()).thenReturn("");
when(ex.getUserMessage()).thenReturn(EXCEPTION_MESSAGE);

ResponseEntity<CallbackResponse> response = underTest.handle(ex);

Expand Down

0 comments on commit 07aa4c3

Please sign in to comment.