Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
H
HYH.APSJ
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
佟礼
HYH.APSJ
Commits
65fd45ea
Commit
65fd45ea
authored
May 14, 2026
by
DESKTOP-VKRD9QF\Administration
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
返回信息修改
parent
29e004ec
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
122 additions
and
0 deletions
+122
-0
BusinessException.java
...main/java/com/aps/common/exception/BusinessException.java
+15
-0
ExceptionMessageUtil.java
src/main/java/com/aps/common/util/ExceptionMessageUtil.java
+107
-0
No files found.
src/main/java/com/aps/common/exception/BusinessException.java
0 → 100644
View file @
65fd45ea
package
com
.
aps
.
common
.
exception
;
/**
* Business exception with a client-safe message.
*/
public
class
BusinessException
extends
RuntimeException
{
public
BusinessException
(
String
message
)
{
super
(
message
);
}
public
BusinessException
(
String
message
,
Throwable
cause
)
{
super
(
message
,
cause
);
}
}
src/main/java/com/aps/common/util/ExceptionMessageUtil.java
0 → 100644
View file @
65fd45ea
package
com
.
aps
.
common
.
util
;
import
java.util.Arrays
;
import
java.util.List
;
/**
* Keeps client error messages short and business-readable.
*/
public
final
class
ExceptionMessageUtil
{
private
static
final
int
MAX_CLIENT_MESSAGE_LENGTH
=
180
;
private
static
final
List
<
String
>
TECHNICAL_MARKERS
=
Arrays
.
asList
(
"Exception"
,
"exception"
,
"NullPointer"
,
"Cannot invoke"
,
"ClassCast"
,
"NumberFormatException"
,
"Index "
,
"out of bounds"
,
"SQL"
,
"ORA-"
,
"JDBC"
,
"MyBatis"
,
"PreparedStatement"
,
"ResultSet"
,
"StackTrace"
,
"nested exception"
,
"java."
,
"javax."
,
"org."
,
"com."
,
"###"
);
private
ExceptionMessageUtil
()
{
}
public
static
String
toClientMessage
(
Throwable
throwable
,
String
fallback
)
{
return
cleanMessage
(
firstMessage
(
throwable
),
fallback
);
}
public
static
String
cleanMessage
(
String
message
,
String
fallback
)
{
String
safeFallback
=
isBlank
(
fallback
)
?
"系统处理失败,请稍后重试或联系管理员"
:
fallback
;
if
(
isBlank
(
message
))
{
return
safeFallback
;
}
String
normalized
=
normalize
(
message
);
normalized
=
stripAfter
(
normalized
,
"; nested exception is"
);
normalized
=
stripAfter
(
normalized
,
"nested exception is"
);
normalized
=
stripAfter
(
normalized
,
"###"
);
if
(
isBlank
(
normalized
)
||
looksTechnical
(
normalized
))
{
return
safeFallback
;
}
if
(
normalized
.
length
()
>
MAX_CLIENT_MESSAGE_LENGTH
)
{
return
normalized
.
substring
(
0
,
MAX_CLIENT_MESSAGE_LENGTH
)
+
"..."
;
}
return
normalized
;
}
private
static
String
firstMessage
(
Throwable
throwable
)
{
Throwable
current
=
throwable
;
while
(
current
!=
null
)
{
if
(!
isBlank
(
current
.
getMessage
()))
{
return
current
.
getMessage
();
}
current
=
current
.
getCause
();
}
return
null
;
}
private
static
String
normalize
(
String
message
)
{
return
message
.
replace
(
'\r'
,
' '
)
.
replace
(
'\n'
,
' '
)
.
replace
(
'\t'
,
' '
)
.
replaceAll
(
"\\s+"
,
" "
)
.
trim
();
}
private
static
String
stripAfter
(
String
message
,
String
marker
)
{
int
index
=
message
.
indexOf
(
marker
);
if
(
index
<
0
)
{
return
message
;
}
return
message
.
substring
(
0
,
index
).
trim
();
}
private
static
boolean
looksTechnical
(
String
message
)
{
if
(
message
.
contains
(
":\\"
)
||
message
.
contains
(
":/"
))
{
return
true
;
}
for
(
String
marker
:
TECHNICAL_MARKERS
)
{
if
(
message
.
contains
(
marker
))
{
return
true
;
}
}
return
false
;
}
private
static
boolean
isBlank
(
String
value
)
{
return
value
==
null
||
value
.
trim
().
isEmpty
();
}
}
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