/*
 * Copyright (c) cn-fanya All rights reserved.
 */

package org.security.common.exception;

import org.security.common.Constant;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springblade.core.tool.api.R;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;


/**
 * 异常处理器
 *
 * @author
 * @since 1.0.0
 */
@RestControllerAdvice
public class RenExceptionHandler {
	private static final Logger logger = LoggerFactory.getLogger(RenExceptionHandler.class);


	/**
	 * 处理自定义异常
	 */
	@ExceptionHandler(RenException.class)
	public R handleRenException(RenException ex) {
		logger.error(ex.getMsg());
		return R.fail(ex.getCode(), ex.getMsg());
	}

	/**
	 * 避免异常信息返回前端
	 * 22-12-28 异常传回前端以便定位问题
	 * @param e
	 * @return
	 */
	@ExceptionHandler(Exception.class)
	public R hendleException(Exception e) {
		logger.error("系统异常：", e);
		return R.fail("系统异常：" + e.getMessage());
	}
}
