Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.springframework.http.ProblemDetail;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;

@RestControllerAdvice
class GlobalExceptionHandler {
Expand Down Expand Up @@ -42,4 +43,14 @@ ProblemDetail handle(BadRequestException e) {
problemDetail.setProperty("timestamp", Instant.now());
return problemDetail;
}

@ExceptionHandler(MethodArgumentTypeMismatchException.class)
ProblemDetail handle(MethodArgumentTypeMismatchException e) {
log.error("Bad Request", e);
ProblemDetail problemDetail = ProblemDetail.forStatusAndDetail(
BAD_REQUEST, "Invalid value for request parameter '" + e.getName() + "'");
problemDetail.setTitle("Bad Request");
problemDetail.setProperty("timestamp", Instant.now());
return problemDetail;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class EmailDeliveryFailureController {
responses = {
@ApiResponse(responseCode = "200", description = "Successful response"),
@ApiResponse(responseCode = "401", description = "Unauthorized"),
@ApiResponse(responseCode = "400", description = "Invalid date format"),
@ApiResponse(responseCode = "403", description = "Forbidden - ADMIN role required")
})
ResponseEntity<Page<EmailDeliveryFailureDto>> getFailures(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.jdbc.core.JdbcTemplate;
Expand Down Expand Up @@ -171,6 +173,18 @@ INSERT INTO email_delivery_failures (id, notification_id, recipient_email, event
assertThat(content.get(0).get("recipientEmail")).isEqualTo("user1@example.com");
}

@ParameterizedTest(name = "should reject malformed date query param: {0}")
@ValueSource(strings = {"invalid-date", "2026-13-01", "2026-02-30", "2026/01/12", "2026-01-12T00:00:00Z"})
@WithMockOAuth2User(
username = "admin",
roles = {"ADMIN"})
void shouldReturn400ForInvalidDateFormat(String invalidDate) throws Exception {
var response =
mvc.get().uri("/api/admin/email-failures?date=" + invalidDate).exchange();

assertThat(response).hasStatus(HttpStatus.BAD_REQUEST);
}

// ========== GET /api/admin/email-failures/{id} ==========

@Test
Expand Down
Loading