Spring Boot HTTP over JSON 的错误码异常处理

This commit is contained in:
JeffLi1993
2017-03-14 11:52:14 +08:00
committed by liqiangqiang
parent 5346d02ac2
commit 07ffcd1a4d
6 changed files with 17 additions and 7 deletions

View File

@@ -1,8 +1,10 @@
package org.spring.springboot.constant;
import org.spring.springboot.result.base.ErrorInfoInterface;
import org.spring.springboot.result.ErrorInfoInterface;
/**
* 业务错误码 案例
*
* Created by bysocket on 14/03/2017.
*/
public enum CityErrorInfoEnum implements ErrorInfoInterface {

View File

@@ -1,8 +1,8 @@
package org.spring.springboot.result;
import org.spring.springboot.result.base.ErrorInfoInterface;
/**
* 统一错误码异常
*
* Created by bysocket on 14/03/2017.
*/
public class GlobalErrorInfoException extends Exception {

View File

@@ -1,12 +1,13 @@
package org.spring.springboot.result;
import org.spring.springboot.result.base.ErrorInfoInterface;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import javax.servlet.http.HttpServletRequest;
/**
* 统一错误码异常处理
*
* Created by bysocket on 14/03/2017.
*/
@RestControllerAdvice

View File

@@ -1,8 +1,8 @@
package org.spring.springboot.result;
import org.spring.springboot.result.base.ErrorInfoInterface;
/**
* 返回体
*
* Created by bysocket on 14/03/2017.
*/
public class ResultBody<T> {

View File

@@ -6,12 +6,19 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* 错误码案例
*
* Created by bysocket on 16/4/26.
*/
@RestController
public class ErrorJsonController {
/**
* 模拟入参不完整案例
*
* @return
* @throws GlobalErrorInfoException
*/
@RequestMapping("/param")
public String errorJsonParams() throws GlobalErrorInfoException {
throw new GlobalErrorInfoException(CityErrorInfoEnum.PARAMS_NO_COMPLETE);