Translates a Throwable into a typed DgraphException. If the throwable is already a DgraphException, returns it as-is. If it is a StatusRuntimeException, maps it by status code. Otherwise wraps it in a generic DgraphException.
(Throwable t)
| 45 | * Otherwise wraps it in a generic DgraphException. |
| 46 | */ |
| 47 | public static DgraphException translate(Throwable t) { |
| 48 | // Unwrap CompletionException to get at the real cause |
| 49 | if (t instanceof CompletionException && t.getCause() != null) { |
| 50 | return translate(t.getCause()); |
| 51 | } |
| 52 | |
| 53 | if (t instanceof DgraphException) { |
| 54 | return (DgraphException) t; |
| 55 | } |
| 56 | |
| 57 | if (t instanceof StatusRuntimeException) { |
| 58 | return fromStatusRuntimeException((StatusRuntimeException) t); |
| 59 | } |
| 60 | |
| 61 | return new DgraphException(t.getMessage(), t); |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Maps a StatusRuntimeException to a typed DgraphException. Status codes are the primary |