Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
97ac1c22
S
spring-framework
项目概览
爱吃血肠
/
spring-framework
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
97ac1c22
编写于
11月 23, 2018
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
DefaultResponseErrorHandler makes use of HttpStatus.isError()
Issue: SPR-17439
上级
a528407d
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
48 addition
and
32 deletion
+48
-32
spring-web/src/main/java/org/springframework/http/HttpStatus.java
...eb/src/main/java/org/springframework/http/HttpStatus.java
+24
-17
spring-web/src/main/java/org/springframework/web/client/DefaultResponseErrorHandler.java
...ringframework/web/client/DefaultResponseErrorHandler.java
+22
-13
spring-web/src/main/java/org/springframework/web/client/ResponseErrorHandler.java
.../org/springframework/web/client/ResponseErrorHandler.java
+2
-2
未找到文件。
spring-web/src/main/java/org/springframework/http/HttpStatus.java
浏览文件 @
97ac1c22
/*
* Copyright 2002-201
7
the original author or authors.
* Copyright 2002-201
8
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -435,50 +435,62 @@ public enum HttpStatus {
return
this
.
reasonPhrase
;
}
/**
* Return the HTTP status series of this status code.
* @see HttpStatus.Series
*/
public
Series
series
()
{
return
Series
.
valueOf
(
this
);
}
/**
* Whether this status code is in the HTTP series
* {@link org.springframework.http.HttpStatus.Series#INFORMATIONAL}.
* This is a shortcut for checking the value of {@link #series()}.
* @see #series()
*/
public
boolean
is1xxInformational
()
{
return
Series
.
INFORMATIONAL
.
equals
(
series
()
);
return
(
series
()
==
Series
.
INFORMATIONAL
);
}
/**
* Whether this status code is in the HTTP series
* {@link org.springframework.http.HttpStatus.Series#SUCCESSFUL}.
* This is a shortcut for checking the value of {@link #series()}.
* @see #series()
*/
public
boolean
is2xxSuccessful
()
{
return
Series
.
SUCCESSFUL
.
equals
(
series
()
);
return
(
series
()
==
Series
.
SUCCESSFUL
);
}
/**
* Whether this status code is in the HTTP series
* {@link org.springframework.http.HttpStatus.Series#REDIRECTION}.
* This is a shortcut for checking the value of {@link #series()}.
* @see #series()
*/
public
boolean
is3xxRedirection
()
{
return
Series
.
REDIRECTION
.
equals
(
series
()
);
return
(
series
()
==
Series
.
REDIRECTION
);
}
/**
* Whether this status code is in the HTTP series
* {@link org.springframework.http.HttpStatus.Series#CLIENT_ERROR}.
* This is a shortcut for checking the value of {@link #series()}.
* @see #series()
*/
public
boolean
is4xxClientError
()
{
return
Series
.
CLIENT_ERROR
.
equals
(
series
()
);
return
(
series
()
==
Series
.
CLIENT_ERROR
);
}
/**
* Whether this status code is in the HTTP series
* {@link org.springframework.http.HttpStatus.Series#SERVER_ERROR}.
* This is a shortcut for checking the value of {@link #series()}.
* @see #series()
*/
public
boolean
is5xxServerError
()
{
return
Series
.
SERVER_ERROR
.
equals
(
series
()
);
return
(
series
()
==
Series
.
SERVER_ERROR
);
}
/**
...
...
@@ -486,17 +498,12 @@ public enum HttpStatus {
* {@link org.springframework.http.HttpStatus.Series#CLIENT_ERROR} or
* {@link org.springframework.http.HttpStatus.Series#SERVER_ERROR}.
* This is a shortcut for checking the value of {@link #series()}.
* @since 5.0
* @see #is4xxClientError()
* @see #is5xxServerError()
*/
public
boolean
isError
()
{
return
is4xxClientError
()
||
is5xxServerError
();
}
/**
* Returns the HTTP status series of this status code.
* @see HttpStatus.Series
*/
public
Series
series
()
{
return
Series
.
valueOf
(
this
);
return
(
is4xxClientError
()
||
is5xxServerError
());
}
/**
...
...
@@ -504,7 +511,7 @@ public enum HttpStatus {
*/
@Override
public
String
toString
()
{
return
Integer
.
toString
(
this
.
value
)
+
" "
+
name
();
return
this
.
value
+
" "
+
name
();
}
...
...
spring-web/src/main/java/org/springframework/web/client/DefaultResponseErrorHandler.java
浏览文件 @
97ac1c22
...
...
@@ -44,7 +44,11 @@ import org.springframework.util.FileCopyUtils;
public
class
DefaultResponseErrorHandler
implements
ResponseErrorHandler
{
/**
* Delegates to {@link #hasError(HttpStatus)} with the response status code.
* Delegates to {@link #hasError(HttpStatus)} (for a standard status enum value) or
* {@link #hasError(int)} (for an unknown status code) with the response status code.
* @see ClientHttpResponse#getRawStatusCode()
* @see #hasError(HttpStatus)
* @see #hasError(int)
*/
@Override
public
boolean
hasError
(
ClientHttpResponse
response
)
throws
IOException
{
...
...
@@ -55,16 +59,14 @@ public class DefaultResponseErrorHandler implements ResponseErrorHandler {
/**
* Template method called from {@link #hasError(ClientHttpResponse)}.
* <p>The default implementation checks if the given status code is
* {@code HttpStatus.Series#CLIENT_ERROR CLIENT_ERROR} or
* {@code HttpStatus.Series#SERVER_ERROR SERVER_ERROR}.
* <p>The default implementation checks {@link HttpStatus#isError()}.
* Can be overridden in subclasses.
* @param statusCode the HTTP status code as enum value
* @return {@code true} if the response has an error; {@code false} otherwise
* @return {@code true} if the response indicates an error; {@code false} otherwise
* @see HttpStatus#isError()
*/
protected
boolean
hasError
(
HttpStatus
statusCode
)
{
return
(
statusCode
.
series
()
==
HttpStatus
.
Series
.
CLIENT_ERROR
||
statusCode
.
series
()
==
HttpStatus
.
Series
.
SERVER_ERROR
);
return
statusCode
.
isError
();
}
/**
...
...
@@ -74,8 +76,10 @@ public class DefaultResponseErrorHandler implements ResponseErrorHandler {
* {@code HttpStatus.Series#SERVER_ERROR SERVER_ERROR}.
* Can be overridden in subclasses.
* @param unknownStatusCode the HTTP status code as raw value
* @return {@code true} if the response
ha
s an error; {@code false} otherwise
* @return {@code true} if the response
indicate
s an error; {@code false} otherwise
* @since 4.3.21
* @see HttpStatus.Series#CLIENT_ERROR
* @see HttpStatus.Series#SERVER_ERROR
*/
protected
boolean
hasError
(
int
unknownStatusCode
)
{
HttpStatus
.
Series
series
=
HttpStatus
.
Series
.
resolve
(
unknownStatusCode
);
...
...
@@ -83,7 +87,10 @@ public class DefaultResponseErrorHandler implements ResponseErrorHandler {
}
/**
* Delegates to {@link #handleError(ClientHttpResponse, HttpStatus)} with the response status code.
* Delegates to {@link #handleError(ClientHttpResponse, HttpStatus)} with the
* response status code.
* @throws UnknownHttpStatusCodeException in case of an unresolvable status code
* @see #handleError(ClientHttpResponse, HttpStatus)
*/
@Override
public
void
handleError
(
ClientHttpResponse
response
)
throws
IOException
{
...
...
@@ -97,11 +104,13 @@ public class DefaultResponseErrorHandler implements ResponseErrorHandler {
/**
* Handle the error in the given response with the given resolved status code.
* <p>Th
is default implementation throws a {@link HttpClientErrorException} if the response status code
* i
s {@link org.springframework.http.HttpStatus.Series#CLIENT_ERROR}, a {@link HttpServerErrorException}
*
if it is {@link org.springframework.http.
HttpStatus.Series#SERVER_ERROR},
* and a
{@link RestClient
Exception} in other cases.
* <p>Th
e default implementation throws an {@link HttpClientErrorException}
* i
f the status code is {@link HttpStatus.Series#CLIENT_ERROR}, an
*
{@link HttpServerErrorException} if it is {@link
HttpStatus.Series#SERVER_ERROR},
* and a
n {@link UnknownHttpStatusCode
Exception} in other cases.
* @since 5.0
* @see HttpClientErrorException#create
* @see HttpServerErrorException#create
*/
protected
void
handleError
(
ClientHttpResponse
response
,
HttpStatus
statusCode
)
throws
IOException
{
String
statusText
=
response
.
getStatusText
();
...
...
spring-web/src/main/java/org/springframework/web/client/ResponseErrorHandler.java
浏览文件 @
97ac1c22
/*
* Copyright 2002-201
7
the original author or authors.
* Copyright 2002-201
8
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -36,7 +36,7 @@ public interface ResponseErrorHandler {
* <p>Implementations will typically inspect the
* {@link ClientHttpResponse#getStatusCode() HttpStatus} of the response.
* @param response the response to inspect
* @return {@code true} if the response
ha
s an error; {@code false} otherwise
* @return {@code true} if the response
indicate
s an error; {@code false} otherwise
* @throws IOException in case of I/O errors
*/
boolean
hasError
(
ClientHttpResponse
response
)
throws
IOException
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录