[R9] Custom exception to handle errors related to consultation business rules
This commit is contained in:
parent
b0fc5bf648
commit
fefa72b8c1
@ -0,0 +1,8 @@
|
|||||||
|
package com.mirna.hospitalmanagementapi.domain.exceptions;
|
||||||
|
|
||||||
|
public class ConsultationValidationException extends Exception {
|
||||||
|
|
||||||
|
public ConsultationValidationException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,23 @@
|
|||||||
|
package com.mirna.hospitalmanagementapi.infra.handlers.validation;
|
||||||
|
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
|
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||||
|
|
||||||
|
import com.mirna.hospitalmanagementapi.domain.exceptions.ConsultationValidationException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This @RestControllerAdvice is used to handle errors related to consultation business rules and return appropriate response message
|
||||||
|
*
|
||||||
|
* @author Mirna Gama
|
||||||
|
* @version 1.0
|
||||||
|
*/
|
||||||
|
@RestControllerAdvice
|
||||||
|
public class ConsultationValidationErrorHandler {
|
||||||
|
|
||||||
|
@ExceptionHandler(ConsultationValidationException.class)
|
||||||
|
public ResponseEntity<Object> handle(ConsultationValidationException exception) {
|
||||||
|
return new ResponseEntity<>(exception.getMessage(), HttpStatus.BAD_REQUEST);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user