fix(api): handle exceptions with status codes (#2160)

This commit is contained in:
James Ward
2026-07-30 16:01:26 -04:00
committed by GitHub
parent 0acd8bcb1e
commit 6056f8f72f
2 changed files with 46 additions and 2 deletions
@@ -0,0 +1,23 @@
package org.booklore.exception;
import org.junit.jupiter.api.Test;
import org.springframework.http.MediaType;
import org.springframework.web.HttpMediaTypeNotAcceptableException;
import java.util.List;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
public class GlobalExceptionHandlerTest {
@Test
void handleGenericException_shouldUseSpringErrorResponse() {
var ex = new HttpMediaTypeNotAcceptableException(List.of(MediaType.APPLICATION_OCTET_STREAM));
var handler = new GlobalExceptionHandler();
var response = handler.handleGenericException(ex);
assertThat(response.getStatusCode().value()).isEqualTo(406);
assertThat(response.getBody()).isNotNull();
assertThat(response.getBody().getStatus()).isEqualTo(406);
assertThat(response.getBody().getMessage()).isEqualTo("Acceptable representations: [application/octet-stream].");
}
}