|
@@ -0,0 +1,29 @@
|
|
|
+package com.mooctest.crowd.domain.controller.advice;
|
|
|
+
|
|
|
+import com.mooctest.crowd.domain.constants.ResponseConstant;
|
|
|
+import com.mooctest.crowd.domain.data.ResponseMessage;
|
|
|
+import com.mooctest.crowd.domain.exception.AccountNotExistException;
|
|
|
+import com.mooctest.crowd.domain.exception.BaseException;
|
|
|
+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;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author: Diors.Po
|
|
|
+ * @Email: 171256175@qq.com
|
|
|
+ * @date 2019-07-25 00:08
|
|
|
+ */
|
|
|
+@RestControllerAdvice
|
|
|
+public class ExceptionAdvice {
|
|
|
+
|
|
|
+
|
|
|
+ @ExceptionHandler(BaseException.class)
|
|
|
+ @ResponseStatus(HttpStatus.BAD_REQUEST)
|
|
|
+ public ResponseMessage handleException(Exception e){
|
|
|
+ if (e instanceof AccountNotExistException){
|
|
|
+ return new ResponseMessage(ResponseConstant.FAIL, ResponseConstant.USER_NOT_EXISTS);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+}
|