package com.mindskip.xzs.controller;
|
|
import com.mindskip.xzs.base.SystemCode;
|
import org.springframework.boot.autoconfigure.web.ErrorProperties;
|
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.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
import org.springframework.web.bind.annotation.RestController;
|
|
import javax.servlet.http.HttpServletRequest;
|
import java.util.HashMap;
|
import java.util.Map;
|
|
/**
|
* @version 2.2.0
|
* @description: 错误控制器
|
* Copyright (C), 2020-2021, 武汉思维跳跃科技有限公司
|
* @date 2021 /9/7 9:45
|
*/
|
@RestController
|
public class ErrorController extends BasicErrorController {
|
|
private static final String PATH = "/error";
|
|
/**
|
* Instantiates a new Error controller.
|
*/
|
public ErrorController() {
|
super(new DefaultErrorAttributes(), new ErrorProperties());
|
}
|
|
@RequestMapping(produces = {MediaType.APPLICATION_JSON_VALUE})
|
@ResponseBody
|
public ResponseEntity<Map<String, Object>> error(HttpServletRequest request) {
|
Map<String, Object> error = new HashMap<>(2);
|
error.put("code", SystemCode.InnerError.getCode());
|
error.put("message", SystemCode.InnerError.getMessage());
|
return new ResponseEntity<>(error, HttpStatus.OK);
|
}
|
|
@Override
|
public String getErrorPath() {
|
return PATH;
|
}
|
}
|