fix(api): handle exceptions with status codes (#2160)
This commit is contained in:
@@ -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].");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user