added log tracing classes

This commit is contained in:
himanshu
2025-11-03 18:13:10 +05:30
parent 0e590961e0
commit f7c2669d11
13 changed files with 276 additions and 51 deletions
@@ -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);
}
}