Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
Y
yzg-util
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
YZG
yzg-util
Commits
9fa04351
Commit
9fa04351
authored
Oct 13, 2020
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改请求错误的显示
parent
0abb62e8
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
111 additions
and
1 deletion
+111
-1
CodeException.java
...in/java/com/yanzuoguang/util/exception/CodeException.java
+49
-0
HttpCodeException.java
...ava/com/yanzuoguang/util/exception/HttpCodeException.java
+58
-0
HttpHelper.java
...src/main/java/com/yanzuoguang/util/helper/HttpHelper.java
+4
-1
No files found.
yzg-util-base/src/main/java/com/yanzuoguang/util/exception/CodeException.java
View file @
9fa04351
...
...
@@ -58,6 +58,36 @@ public class CodeException extends RuntimeException {
this
.
code
=
code
;
}
/**
* 构造函数
* throw new CodeException("01","该订单已过期",order);
* throw new CodeException("02","该订单未到使用时间",order);
*
* @param message 错误消息
* @param target 错误数据源,如订单数据
*/
public
CodeException
(
String
message
,
Object
target
)
{
super
(
message
);
this
.
target
=
target
;
}
/**
* 构造函数
* throw new CodeException("01","该订单已过期",order);
* throw new CodeException("02","该订单未到使用时间",order);
*
* @param message 错误消息
* @param target 错误数据源,如订单数据
* @param cause the cause (which is saved for later retrieval by the
* {@link #getCause()} method). (A <tt>null</tt> value is
* permitted, and indicates that the cause is nonexistent or
* unknown.)
*/
public
CodeException
(
String
message
,
Object
target
,
Throwable
cause
)
{
super
(
message
,
cause
);
this
.
target
=
target
;
}
/**
* 构造函数
* throw new CodeException("01","该订单已过期",order);
...
...
@@ -73,6 +103,25 @@ public class CodeException extends RuntimeException {
this
.
target
=
target
;
}
/**
* 构造函数
* throw new CodeException("01","该订单已过期",order);
* throw new CodeException("02","该订单未到使用时间",order);
*
* @param code 错误码
* @param message 错误消息
* @param target 错误数据源,如订单数据
* @param cause the cause (which is saved for later retrieval by the
* {@link #getCause()} method). (A <tt>null</tt> value is
* permitted, and indicates that the cause is nonexistent or
* unknown.)
*/
public
CodeException
(
String
code
,
String
message
,
Object
target
,
Throwable
cause
)
{
super
(
message
,
cause
);
this
.
code
=
code
;
this
.
target
=
target
;
}
/**
* Constructs a new runtime exception with the specified detail message and
* cause. <p>Note that the detail message associated with
...
...
yzg-util-base/src/main/java/com/yanzuoguang/util/exception/HttpCodeException.java
0 → 100755
View file @
9fa04351
package
com
.
yanzuoguang
.
util
.
exception
;
/**
* 途比达异常信息
*
* @author 颜佐光
*/
public
class
HttpCodeException
extends
RuntimeException
{
private
static
final
long
serialVersionUID
=
-
4625832188480820883L
;
/**
* 错误码
*/
private
String
code
=
"99"
;
/**
* 包含的数据
*/
private
Object
target
=
null
;
/**
* 获取错误码
*
* @return 返回的结果
*/
public
String
getCode
()
{
return
this
.
code
;
}
/**
* 来源数据
*
* @return
*/
public
Object
getTarget
()
{
return
target
;
}
/**
* 构造函数
* throw new CodeException("01","该订单已过期",order);
* throw new CodeException("02","该订单未到使用时间",order);
*
* @param code 错误码
* @param message 错误消息
* @param target 错误数据源,如订单数据
* @param cause the cause (which is saved for later retrieval by the
* {@link #getCause()} method). (A <tt>null</tt> value is
* permitted, and indicates that the cause is nonexistent or
* unknown.)
*/
public
HttpCodeException
(
String
code
,
String
message
,
Object
target
,
Throwable
cause
)
{
super
(
message
,
cause
);
this
.
code
=
code
;
this
.
target
=
target
;
}
}
yzg-util-base/src/main/java/com/yanzuoguang/util/helper/HttpHelper.java
View file @
9fa04351
package
com
.
yanzuoguang
.
util
.
helper
;
import
com.yanzuoguang.util.exception.CodeException
;
import
com.yanzuoguang.util.exception.HttpCodeException
;
import
com.yanzuoguang.util.thread.ProcessData
;
import
com.yanzuoguang.util.thread.RunProcess
;
import
javax.xml.ws.http.HTTPException
;
import
java.io.*
;
import
java.net.HttpURLConnection
;
import
java.net.URL
;
...
...
@@ -100,7 +103,7 @@ public class HttpHelper {
in
=
readStream
(
httpConn
.
getInputStream
(),
result
);
}
catch
(
Exception
ex
)
{
in
=
readStream
(
httpConn
.
getErrorStream
(),
result
);
throw
new
RuntimeException
(
ex
.
getMessage
()
+
" 结果:"
+
result
.
toString
(),
ex
);
throw
new
HttpCodeException
(
StringHelper
.
toString
(
httpConn
.
getResponseCode
()),
ex
.
getMessage
(),
result
.
toString
(),
ex
);
}
finally
{
if
(
out
!=
null
)
{
out
.
close
();
...
...
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