Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ff8ab6b

Browse files
add exception with exceptionController
1 parent e641922 commit ff8ab6b

File tree

4 files changed

+50
-0
lines changed

4 files changed

+50
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.nasr.webfluxdemo.exception;
2+
3+
import com.nasr.webfluxdemo.dto.response.ResponseDto;
4+
import org.springframework.http.HttpStatus;
5+
import org.springframework.http.ResponseEntity;
6+
import org.springframework.web.bind.annotation.ControllerAdvice;
7+
import org.springframework.web.bind.annotation.ExceptionHandler;
8+
9+
@ControllerAdvice
10+
public class ExceptionController {
11+
12+
@ExceptionHandler(ProductNotFoundException.class)
13+
public ResponseEntity<ResponseDto<?>> productNotFoundException(ProductNotFoundException e) {
14+
return ResponseEntity.status(HttpStatus.NOT_FOUND)
15+
.body(new ResponseDto<>(false, null, e.getMessage()));
16+
}
17+
18+
@ExceptionHandler(OrderNotFoundException.class)
19+
public ResponseEntity<ResponseDto<?>> orderNotFoundException(OrderNotFoundException e) {
20+
return ResponseEntity.status(HttpStatus.NOT_FOUND)
21+
.body(new ResponseDto<>(false, null, e.getMessage()));
22+
}
23+
24+
@ExceptionHandler(IllegalProductException.class)
25+
public ResponseEntity<ResponseDto<?>> illegalProductException(IllegalProductException e) {
26+
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
27+
.body(new ResponseDto<>(false, null, e.getMessage()));
28+
}
29+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.nasr.webfluxdemo.exception;
2+
3+
public class IllegalProductException extends RuntimeException{
4+
public IllegalProductException(String message) {
5+
super(message);
6+
}
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.nasr.webfluxdemo.exception;
2+
3+
public class OrderNotFoundException extends RuntimeException{
4+
public OrderNotFoundException(String message) {
5+
super(message);
6+
}
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.nasr.webfluxdemo.exception;
2+
3+
public class ProductNotFoundException extends RuntimeException{
4+
public ProductNotFoundException(String message) {
5+
super(message);
6+
}
7+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /