Skip to content

Commit

Permalink
added tests; generalized the exception
Browse files Browse the repository at this point in the history
Signed-off-by: Iva Avramova <[email protected]>
  • Loading branch information
ivakoleva committed Apr 22, 2024
1 parent 2e919e5 commit ef267ad
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.servlet.resource.NoResourceFoundException;

Expand Down Expand Up @@ -58,6 +59,7 @@ public class ApplicationExceptionMapper {

@ExceptionHandler(ClientAbortException.class)
@Order(ValidationExceptionMapper.ORDER + 1)
@ResponseStatus(HttpStatus.NO_CONTENT)
public void handleClientAborted(
HttpServletRequest request, ClientAbortException clientAbortException) {
logException(
Expand All @@ -78,7 +80,7 @@ public ResponseEntity<ErrorResponse> handleAll(HttpServletRequest request, Throw
.findAny();
if (clientAbortedException.isPresent()) {
handleClientAborted(request, (ClientAbortException) clientAbortedException.get());
return ResponseEntity.ok().build();
return ResponseEntity.noContent().build();
}

logException(request, th);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public void testClientAbortException() throws Exception {
new ObjectMapper()
.writeValueAsString(Collections.emptyMap())))
.andDo(print())
.andExpect(status().isOk());
.andExpect(status().isNoContent());
// verify the error was logged
verify(logger)
.error(
Expand Down Expand Up @@ -138,7 +138,7 @@ public void testClientAbortExceptionChained() throws Exception {
new ObjectMapper()
.writeValueAsString(Collections.emptyMap())))
.andDo(print())
.andExpect(status().isOk());
.andExpect(status().isNoContent());
// verify the error was logged
verify(logger)
.error(
Expand Down

0 comments on commit ef267ad

Please sign in to comment.