未验证 提交 08720578 编写于 作者: J Jason Song 提交者: GitHub

Merge pull request #1212 from nobodyiam/fix-404-exception

when server returns status code other than 200 and 304, we should throw ApolloConfigStatusCodeException
......@@ -11,6 +11,11 @@ public class ApolloConfigStatusCodeException extends RuntimeException{
this.m_statusCode = statusCode;
}
public ApolloConfigStatusCodeException(int statusCode, Throwable cause) {
super(cause);
this.m_statusCode = statusCode;
}
public int getStatusCode() {
return m_statusCode;
}
......
......@@ -116,7 +116,13 @@ public class HttpUtil {
}
}
throw ex;
// 200 and 304 should not trigger IOException, thus we must throw the original exception out
if (statusCode == 200 || statusCode == 304) {
throw ex;
} else {
// for status codes like 404, IOException is expected when calling conn.getInputStream()
throw new ApolloConfigStatusCodeException(statusCode, ex);
}
}
if (statusCode == 200) {
......@@ -126,6 +132,8 @@ public class HttpUtil {
if (statusCode == 304) {
return new HttpResponse<>(statusCode, null);
}
} catch (ApolloConfigStatusCodeException ex) {
throw ex;
} catch (Throwable ex) {
throw new ApolloConfigException("Could not complete get operation", ex);
} finally {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册