Exception Handling in Spring Webflux

แชร์
ฝัง
  • เผยแพร่เมื่อ 2 ก.พ. 2025

ความคิดเห็น • 8

  • @ayushmittal7059
    @ayushmittal7059 2 ปีที่แล้ว

    It’s really helpful but can you help in writing unit test cases in JUnit 5 so that coverage will increase for these 2 classes ?

  • @aloshy7717
    @aloshy7717 ปีที่แล้ว

    How to handle if we have different custom exceptions

    • @GainJavaKnowledge
      @GainJavaKnowledge  ปีที่แล้ว

      In the controller advice class you can handle.
      @ExceptionHandler(CustomException.class) public ResponseEntity customException(CustomException exception) { return new ResponseEntity( new CustomErrorModel(), HttpStatus.BAD_REQUEST ); }

  • @life.at_7000rpm
    @life.at_7000rpm ปีที่แล้ว

    In case the custom handler does not take effect, add @Order(-2) on your handler class to give it a higher priority than the DefaultErrorWebExceptionHandler.

    • @GainJavaKnowledge
      @GainJavaKnowledge  ปีที่แล้ว

      It should go last. From JavaDoc of @Order: Lower values have higher priority. The default value is Ordered.LOWEST_PRECEDENCE, indicating lowest priority (losing to any other specified order value).

  • @ayushmittal7059
    @ayushmittal7059 2 ปีที่แล้ว

    Is there any JUnit5 test cases for coverage of these 2 classes ?