|
|
@@ -1,41 +0,0 @@
|
|
|
-package com.usoftchina.saas.server.error;
|
|
|
-
|
|
|
-import org.springframework.boot.autoconfigure.web.ServerProperties;
|
|
|
-import org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController;
|
|
|
-import org.springframework.boot.web.servlet.error.DefaultErrorAttributes;
|
|
|
-import org.springframework.http.HttpStatus;
|
|
|
-import org.springframework.http.MediaType;
|
|
|
-import org.springframework.http.ResponseEntity;
|
|
|
-import org.springframework.stereotype.Controller;
|
|
|
-
|
|
|
-import javax.servlet.http.HttpServletRequest;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.Map;
|
|
|
-
|
|
|
-/**
|
|
|
- * @author yingp
|
|
|
- * @date 2018/10/13
|
|
|
- */
|
|
|
-@Controller
|
|
|
-public class MyErrorController extends BasicErrorController {
|
|
|
-
|
|
|
- public MyErrorController(ServerProperties serverProperties) {
|
|
|
- super(new DefaultErrorAttributes(), serverProperties.getError());
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 覆盖默认的错误响应
|
|
|
- */
|
|
|
- @Override
|
|
|
- public ResponseEntity<Map<String, Object>> error(HttpServletRequest request) {
|
|
|
- Map<String, Object> body = getErrorAttributes(request, isIncludeStackTrace(request, MediaType.ALL));
|
|
|
- HttpStatus status = getStatus(request);
|
|
|
- // 输出自定义格式
|
|
|
- Map<String, Object> map = new HashMap<>(4);
|
|
|
- map.put("success", false);
|
|
|
- map.put("code", body.get("status"));
|
|
|
- map.put("message", body.get("message"));
|
|
|
- map.put("data", null);
|
|
|
- return new ResponseEntity<>(map, status);
|
|
|
- }
|
|
|
-}
|