___ _ _
/ __(_) ___ __ _ __| | __ _
/ / | |/ __/ _` |/ _` |/ _` |
/ /___| | (_| (_| | (_| | (_| |
\____/|_|\___\__,_|\__,_|\__,_|一款非常简单易用的异常处理框架。只需简单使用注解,即可抛出优美的异常被客户端接收。
repositories {
maven { url "https://jitpack.io" }
}
dependencies{
implementation 'com.github.niceSong.cicada:cicada-web:v1.0.3'
implementation 'com.github.niceSong.cicada:cicada-exception:v1.0.1'
}@CicadaScan
@SpringBootApplication
public class TestApplication {
public static void main(String[] args) {
SpringApplication.run(TestApplication.class, args);
}
}@CicadaScan用于扫描@CicadaBean注解的接口。
@CicadaBean(namespace = "test")
public interface TestException {
@ExceptionInfo(errCode = 1000)
CicadaException fuckException();
}只需定义接口,框架会动态代理生成Bean注入spring。
@Autowired
TestException testException;
@GetMapping(value = "/test")
public void test(){
throw testException.fuckException("You throw cicada exception successfully");
}Autowired依赖注入,即可调用接口方法抛出异常。
客户端收到异常格式如下:
{
"errCode": 1000,
"nameSpace": "test",
"errMessage": "You throw cicada exception successfully",
"stackTrace": "..."
}使用愉快,有问题欢迎随时issues。