|
18 | 18 |
|
19 | 19 | import com.google.api.gax.rpc.InternalException; |
20 | 20 | import com.google.common.base.Predicate; |
| 21 | +import com.google.common.collect.ImmutableList; |
21 | 22 | import io.grpc.Status; |
22 | 23 | import io.grpc.StatusRuntimeException; |
23 | 24 |
|
24 | 25 | public class IsRetryableInternalError implements Predicate<Throwable> { |
25 | 26 |
|
26 | | - private static final String HTTP2_ERROR_MESSAGE = "HTTP/2 error code: INTERNAL_ERROR"; |
27 | | - private static final String CONNECTION_CLOSED_ERROR_MESSAGE = |
28 | | - "Connection closed with unknown cause"; |
29 | | - private static final String EOS_ERROR_MESSAGE = |
30 | | - "Received unexpected EOS on DATA frame from server"; |
31 | | - |
32 | | - private static final String RST_STREAM_ERROR_MESSAGE = "stream terminated by RST_STREAM"; |
| 27 | + private static final ImmutableList<String> RETRYABLE_ERROR_MESSAGES = |
| 28 | + ImmutableList.of( |
| 29 | + "HTTP/2 error code: INTERNAL_ERROR", |
| 30 | + "Connection closed with unknown cause", |
| 31 | + "Received unexpected EOS on DATA frame from server", |
| 32 | + "stream terminated by RST_STREAM", |
| 33 | + "Authentication backend internal server error. Please retry."); |
33 | 34 |
|
34 | 35 | @Override |
35 | 36 | public boolean apply(Throwable cause) { |
36 | 37 | if (isInternalError(cause)) { |
37 | | - if (cause.getMessage().contains(HTTP2_ERROR_MESSAGE)) { |
38 | | - return true; |
39 | | - } else if (cause.getMessage().contains(CONNECTION_CLOSED_ERROR_MESSAGE)) { |
40 | | - return true; |
41 | | - } else if (cause.getMessage().contains(EOS_ERROR_MESSAGE)) { |
42 | | - return true; |
43 | | - } else if (cause.getMessage().contains(RST_STREAM_ERROR_MESSAGE)) { |
44 | | - return true; |
45 | | - } |
| 38 | + return RETRYABLE_ERROR_MESSAGES.stream() |
| 39 | + .anyMatch(message -> cause.getMessage().contains(message)); |
46 | 40 | } |
47 | 41 | return false; |
48 | 42 | } |
|
0 commit comments