Skip to content

Commit

Permalink
Merge pull request #1212 from nobodyiam/fix-404-exception
Browse files Browse the repository at this point in the history
when server returns status code other than 200 and 304, we should throw ApolloConfigStatusCodeException
nobodyiam authored Jun 30, 2018
2 parents 9d5646f + 1f5e188 commit 0872057
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -11,6 +11,11 @@ public ApolloConfigStatusCodeException(int statusCode, String message) {
this.m_statusCode = statusCode;
}

public ApolloConfigStatusCodeException(int statusCode, Throwable cause) {
super(cause);
this.m_statusCode = statusCode;
}

public int getStatusCode() {
return m_statusCode;
}
Original file line number Diff line number Diff line change
@@ -116,7 +116,13 @@ private <T> HttpResponse<T> doGetWithSerializeFunction(HttpRequest httpRequest,
}
}

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 @@ private <T> HttpResponse<T> doGetWithSerializeFunction(HttpRequest httpRequest,
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 {

0 comments on commit 0872057

Please sign in to comment.