All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.xuchen93.web.handler.ExceptionHandlers Maven / Gradle / Ivy

There is a newer version: 1.1.3
Show newest version
package com.github.xuchen93.web.handler;

import com.github.xuchen93.model.R;
import com.github.xuchen93.model.ex.AuthException;
import com.github.xuchen93.model.ex.BusiException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@Slf4j
@ControllerAdvice
public class ExceptionHandlers {

	@ExceptionHandler(BusiException.class)
	@ResponseBody
	public R throwable(BusiException e) {
		return R.fail(e.getCode(), e.getMessage());
	}

	@ExceptionHandler(AuthException.class)
	@ResponseBody
	public R throwable(AuthException e) {
		return R.fail(e.getCode(), e.getMessage());
	}

	@ExceptionHandler(Exception.class)
	@ResponseBody
	public R throwable(Exception e) {
		log.error("拦截到未知异常", e);
		return R.fail();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy