Skip to content

Commit

Permalink
Merge pull request Netflix#1561 from mattrjacobs/add-error-handling-s…
Browse files Browse the repository at this point in the history
…ample-sse-servlet

Add exception-handling to interactions with servlet writers
  • Loading branch information
mattrjacobs authored May 3, 2017
2 parents d3e0991 + b46a563 commit 1722d69
Showing 1 changed file with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,16 @@ public void onError(Throwable e) {
@Override
public void onNext(String sampleDataAsString) {
if (sampleDataAsString != null) {
writer.print("data: " + sampleDataAsString + "\n\n");
// explicitly check for client disconnect - PrintWriter does not throw exceptions
if (writer.checkError()) {
try {
writer.print("data: " + sampleDataAsString + "\n\n");
// explicitly check for client disconnect - PrintWriter does not throw exceptions
if (writer.checkError()) {
moreDataWillBeSent.set(false);
}
writer.flush();
} catch (Exception ex) {
moreDataWillBeSent.set(false);
}
writer.flush();
}
}
});
Expand All @@ -166,7 +170,7 @@ public void onNext(String sampleDataAsString) {
moreDataWillBeSent.set(false);
}
writer.flush();
} catch (InterruptedException e) {
} catch (Exception ex) {
moreDataWillBeSent.set(false);
}
}
Expand Down

0 comments on commit 1722d69

Please sign in to comment.