Commit 14e359ba authored by duanruiming's avatar duanruiming

[add] 统一异常处理

parent f1e13a8a
package net.wanji.opt.common.exception;
import lombok.extern.slf4j.Slf4j;
import net.wanji.common.framework.exceptionhandler.GlobalExceptionHandler;
import net.wanji.common.framework.rest.JsonViewObject;
import org.apache.catalina.connector.ClientAbortException;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;
/**
......@@ -12,6 +16,7 @@ import org.springframework.web.bind.annotation.RestControllerAdvice;
* @date 2023/1/5 13:18
*/
@RestControllerAdvice
@Slf4j
public class OptExceptionHandler extends GlobalExceptionHandler {
/**
* 字段值重复异常
......@@ -25,4 +30,11 @@ public class OptExceptionHandler extends GlobalExceptionHandler {
public JsonViewObject OptServiceExceptionHandler(OptServiceException e) {
return JsonViewObject.newInstance().fail(e.getMessage(), "optService服务调用异常");
}
@ExceptionHandler(value = ClientAbortException.class)
@ResponseStatus(HttpStatus.OK)
public JsonViewObject clientExceptionHandler(ClientAbortException ex) {
log.error("ClientAbortException异常opt:{}", ex);
return JsonViewObject.newInstance().success("");
}
}
\ No newline at end of file
......@@ -556,6 +556,10 @@
<artifactId>curl</artifactId>
<version>0.0.43</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
......@@ -5,11 +5,14 @@ import net.wanji.common.framework.Constants;
import net.wanji.common.framework.exception.FeignServiceException;
import net.wanji.common.framework.exception.RidException;
import net.wanji.common.framework.rest.JsonViewObject;
import org.apache.catalina.connector.ClientAbortException;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.http.HttpStatus;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.validation.FieldError;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import javax.servlet.http.HttpServletRequest;
......@@ -170,4 +173,11 @@ public class GlobalExceptionHandler {
log.error("RuntimeException异常:", e);
return JsonViewObject.newInstance().fail(errorMessage);
}
@ExceptionHandler(value = ClientAbortException.class)
@ResponseStatus(HttpStatus.OK)
public JsonViewObject clientExceptionHandler(ClientAbortException ex) {
log.error("ClientAbortException异常global:{}", ex);
return JsonViewObject.newInstance().success("");
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment