Extract an error trailers from the causal chain of a Throwable. @return the trailers or null if not found.
(Throwable t)
| 413 | * @return the trailers or {@code null} if not found. |
| 414 | */ |
| 415 | @Nullable |
| 416 | public static Metadata trailersFromThrowable(Throwable t) { |
| 417 | Throwable cause = checkNotNull(t, "t"); |
| 418 | while (cause != null) { |
| 419 | if (cause instanceof StatusException) { |
| 420 | return ((StatusException) cause).getTrailers(); |
| 421 | } else if (cause instanceof StatusRuntimeException) { |
| 422 | return ((StatusRuntimeException) cause).getTrailers(); |
| 423 | } |
| 424 | cause = cause.getCause(); |
| 425 | } |
| 426 | return null; |
| 427 | } |
| 428 | |
| 429 | static String formatThrowableMessage(Status status) { |
| 430 | if (status.description == null) { |