added log tracing classes
This commit is contained in:
@@ -2,16 +2,41 @@ package com.billpaymentservice.bbps.exception;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.MethodArgumentNotValidException;
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import com.billpaymentservice.bbps.dto.GeneralResp;
|
||||
|
||||
import com.billpaymentservice.bbps.dto.ResponseModel;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@ControllerAdvice
|
||||
public class GlobalExceptionHandler {
|
||||
|
||||
// ✅ Handle CustomException
|
||||
@ExceptionHandler(CustomException.class)
|
||||
public ResponseEntity<ResponseModel> handleCustomException(CustomException ex) {
|
||||
public ResponseEntity<ResponseModel<?>> handleCustomException(CustomException ex) {
|
||||
return new ResponseEntity<>(ex.getResponseModel(), HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
|
||||
// ✅ Handle validation errors
|
||||
@ExceptionHandler(MethodArgumentNotValidException.class)
|
||||
public ResponseEntity<ResponseModel<?>> handleValidationExceptions(MethodArgumentNotValidException ex) {
|
||||
|
||||
Map<String, String> errors = new HashMap<>();
|
||||
|
||||
ex.getBindingResult().getFieldErrors().forEach(error -> {
|
||||
errors.put(error.getField(), error.getDefaultMessage());
|
||||
});
|
||||
|
||||
ResponseModel<?> response = new ResponseModel<>(
|
||||
"Validation Failed",
|
||||
"FAILED",
|
||||
HttpStatus.BAD_REQUEST.value(),
|
||||
errors
|
||||
);
|
||||
|
||||
return new ResponseEntity<>(response, HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user