Skip to content

Commit

Permalink
[fix]예외 응답 상태코드 수정 (#12)
Browse files Browse the repository at this point in the history
빈페이지 조회시 응답 코드 변경 400->404
  • Loading branch information
YeaChan05 committed Mar 4, 2024
1 parent 743238e commit 0ebfbfe
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.springframework.data.web.PageableDefault;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.MissingServletRequestParameterException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
Expand Down Expand Up @@ -50,12 +51,17 @@ public ResponseEntity<?> getSimpleProductsInfo(@RequestParam("categoryId") Long
Page<SimpleProductDto> simpleProductsPage = productService.getSimpleProductsPage(categoryId, pageable);
return ResponseEntity.ok(simpleProductsPage);
} catch (IllegalArgumentException e) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(e.getMessage());
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(e.getMessage());
}
}

@ExceptionHandler(MethodArgumentTypeMismatchException.class)
public ResponseEntity<?> handleMethodArgumentTypeMismatchException(MethodArgumentTypeMismatchException e) {
return new ResponseEntity<>(e.getMessage(), HttpStatus.BAD_REQUEST);
}

@ExceptionHandler(MissingServletRequestParameterException.class)
public ResponseEntity<?> handleMissingServletRequestParameterException(MissingServletRequestParameterException e) {
return new ResponseEntity<>(e.getMessage(), HttpStatus.BAD_REQUEST);
}
}

0 comments on commit 0ebfbfe

Please sign in to comment.