Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
sample-form-platform
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
赵啸非
sample-form-platform
Commits
470adad7
Commit
470adad7
authored
Sep 24, 2024
by
赵啸非
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加排除事项
parent
a68213f8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
26 deletions
+42
-26
sample-form-manager/src/main/java/com/mortals/xhx/base/framework/exception/ExceptionHandle.java
...mortals/xhx/base/framework/exception/ExceptionHandle.java
+42
-26
No files found.
sample-form-manager/src/main/java/com/mortals/xhx/base/framework/exception/ExceptionHandle.java
View file @
470adad7
package
com.mortals.xhx.base.framework.exception
;
package
com.mortals.xhx.base.framework.exception
;
import
org.slf4j.Logger
;
import
cn.hutool.core.util.StrUtil
;
import
org.slf4j.LoggerFactory
;
import
cn.hutool.http.HttpStatus
;
import
com.alibaba.fastjson.JSONObject
;
import
com.mortals.framework.exception.AppException
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.converter.HttpMessageNotReadableException
;
import
org.springframework.web.bind.annotation.ControllerAdvice
;
import
org.springframework.web.bind.annotation.ControllerAdvice
;
import
org.springframework.web.bind.annotation.ExceptionHandler
;
import
org.springframework.web.bind.annotation.ExceptionHandler
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
com.alibaba.fastjson.JSONObjec
t
;
import
javax.servlet.http.HttpServletReques
t
;
import
com.mortals.framework.exception.AppException
;
import
javax.servlet.http.HttpServletResponse
;
/**
/**
* 统一异常处理
* 统一异常处理
*/
*/
@ControllerAdvice
@ControllerAdvice
@Slf4j
public
class
ExceptionHandle
{
public
class
ExceptionHandle
{
private
final
static
Logger
log
=
LoggerFactory
.
getLogger
(
ExceptionHandle
.
class
);
@Autowired
private
HttpServletRequest
request
;
@Autowired
private
HttpServletResponse
response
;
public
static
final
String
KEY_RESULT_CODE
=
"code"
;
public
static
final
String
KEY_RESULT_CODE
=
"code"
;
public
static
final
String
KEY_RESULT_MSG
=
"msg"
;
public
static
final
String
KEY_RESULT_MSG
=
"msg"
;
public
static
final
String
KEY_RESULT_DATA
=
"data"
;
public
static
final
String
KEY_RESULT_DATA
=
"data"
;
public
static
final
int
VALUE_RESULT_FAILURE
=
-
1
;
public
static
final
int
VALUE_RESULT_FAILURE
=
-
1
;
@ExceptionHandler
(
value
=
Exception
.
class
)
@ExceptionHandler
(
value
=
Exception
.
class
)
@ResponseBody
@ResponseBody
public
String
handle
(
Exception
e
)
{
public
String
handle
(
Exception
e
)
{
JSONObject
ret
=
new
JSONObject
();
JSONObject
ret
=
new
JSONObject
();
ret
.
put
(
KEY_RESULT_CODE
,
VALUE_RESULT_FAILURE
);
ret
.
put
(
KEY_RESULT_CODE
,
VALUE_RESULT_FAILURE
);
if
(
e
instanceof
AppException
)
{
if
(
e
instanceof
AppException
)
{
StackTraceElement
stack
=
e
.
getStackTrace
()[
0
];
StackTraceElement
stack
=
e
.
getStackTrace
()[
0
];
log
.
error
(
"[business error]=========stack message[{}],[{},method:{},line{}][{}]"
,
e
.
getMessage
(),
log
.
error
(
"[business error]=========stack message[{}],[{},method:{},line{}][{}]"
,
e
.
getMessage
(),
stack
.
getClassName
(),
stack
.
getMethodName
(),
stack
.
getLineNumber
(),
e
.
getClass
().
getName
());
stack
.
getClassName
(),
stack
.
getMethodName
(),
stack
.
getLineNumber
(),
e
.
getClass
().
getName
());
AppException
ex
=
(
AppException
)
e
;
AppException
ex
=
(
AppException
)
e
;
ret
.
put
(
KEY_RESULT_MSG
,
ex
.
getMessage
());
ret
.
put
(
KEY_RESULT_MSG
,
ex
.
getMessage
());
}
else
{
}
log
.
error
(
"[system error]"
,
e
);
if
(
e
instanceof
HttpMessageNotReadableException
)
{
ret
.
put
(
KEY_RESULT_MSG
,
"unknown exception!"
);
log
.
error
(
"[system error]"
,
e
);
}
response
.
setStatus
(
HttpStatus
.
HTTP_BAD_REQUEST
);
return
ret
.
toJSONString
();
ret
.
put
(
KEY_RESULT_MSG
,
"参数错误,"
+
StrUtil
.
subBefore
(
e
.
getMessage
(),
";"
,
false
));
}
}
else
{
log
.
error
(
"[system error]"
,
e
);
response
.
setStatus
(
HttpStatus
.
HTTP_INTERNAL_ERROR
);
ret
.
put
(
KEY_RESULT_MSG
,
"未知错误!"
+
e
.
getMessage
());
}
return
ret
.
toJSONString
();
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment