Extract an error Status from the causal chain of a Throwable. If no status can be found, a status is created with Code#UNKNOWN as its code and t as its cause. @return non-null status
(Throwable t)
| 394 | * @return non-{@code null} status |
| 395 | */ |
| 396 | public static Status fromThrowable(Throwable t) { |
| 397 | Throwable cause = checkNotNull(t, "t"); |
| 398 | while (cause != null) { |
| 399 | if (cause instanceof StatusException) { |
| 400 | return ((StatusException) cause).getStatus(); |
| 401 | } else if (cause instanceof StatusRuntimeException) { |
| 402 | return ((StatusRuntimeException) cause).getStatus(); |
| 403 | } |
| 404 | cause = cause.getCause(); |
| 405 | } |
| 406 | // Couldn't find a cause with a Status |
| 407 | return UNKNOWN.withCause(t); |
| 408 | } |
| 409 | |
| 410 | /** |
| 411 | * Extract an error trailers from the causal chain of a {@link Throwable}. |