Skip to content

Commit d17f199

Browse files
committed
Finalize the advice package to handle exceptions
1 parent 20fb94b commit d17f199

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package lk.ijse.dep.note.advice;
2+
3+
import lk.ijse.dep.note.service.exception.DuplicateEmailException;
4+
import lk.ijse.dep.note.service.exception.NotFoundException;
5+
import org.springframework.http.HttpStatus;
6+
import org.springframework.web.bind.annotation.ExceptionHandler;
7+
import org.springframework.web.bind.annotation.ResponseStatus;
8+
import org.springframework.web.bind.annotation.RestControllerAdvice;
9+
import org.springframework.web.server.ResponseStatusException;
10+
11+
@RestControllerAdvice
12+
public class GlobalExceptionHandler {
13+
14+
@ExceptionHandler(DuplicateEmailException.class)
15+
public void handleDuplicateEmailexception(DuplicateEmailException e){
16+
e.initCause( new ResponseStatusException(HttpStatus.CONFLICT,e.getMessage()));
17+
}
18+
@ExceptionHandler(NotFoundException.class)
19+
public void handleNotfoundExcpetion(NotFoundException e){
20+
e.initCause(new ResponseStatusException(HttpStatus.NOT_FOUND,e.getMessage()));
21+
}
22+
}

0 commit comments

Comments
 (0)