package com.spring.common.error;

import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {
    
    @ExceptionHandler(BizBaseException.class)
    public BizErrorResponse handleCustomException(BizBaseException e) {
        return BizErrorResponse.valueOf(e.getErrorRule());
    }

    @ExceptionHandler(MethodArgumentNotValidException.class)
    public BizErrorResponse methodArgumentNotValidException(MethodArgumentNotValidException e) {
        return BizErrorResponse.fromFieldError(e.getFieldErrors());
    }

}
