| 12345678910111213141516171819202122232425262728293031 |
- package com.izouma.walkchina.exception;
- import com.izouma.walkchina.bean.Result;
- import org.springframework.web.bind.annotation.ControllerAdvice;
- import org.springframework.web.bind.annotation.ExceptionHandler;
- import org.springframework.web.bind.annotation.ResponseBody;
- import javax.servlet.http.HttpServletRequest;
- import java.util.HashMap;
- import java.util.Map;
- @ControllerAdvice
- public class GlobalExceptionHandler {
- @ExceptionHandler(value = ServiceException.class)
- @ResponseBody
- public Result serviceExceptionHandler(HttpServletRequest req, ServiceException e) {
- Map<String, Object> map = new HashMap<>();
- map.put("url", req.getRequestURL().toString());
- return Result.builder()
- .success(false)
- .error(e.getMessage())
- .data(map)
- .code(-1)
- .build();
- }
- }
|