|
35 | 35 | */ |
36 | 36 | public final class GCPErrorDetailsProviderUtil { |
37 | 37 |
|
38 | | - public static ProgramFailureException getHttpResponseExceptionDetailsFromChain(Exception e, String errorReason) { |
39 | | - return getHttpResponseExceptionDetailsFromChain(e, errorReason, ErrorType.USER, true); |
| 38 | + public static ProgramFailureException getHttpResponseExceptionDetailsFromChain(Exception e, String errorReason, |
| 39 | + String externalDocUrl) { |
| 40 | + return getHttpResponseExceptionDetailsFromChain(e, errorReason, ErrorType.USER, true, externalDocUrl); |
40 | 41 | } |
41 | 42 |
|
42 | 43 | public static ProgramFailureException getHttpResponseExceptionDetailsFromChain(Exception e, String errorReason, |
43 | 44 | ErrorType errorType, |
44 | | - boolean dependency) { |
| 45 | + boolean dependency, |
| 46 | + String externalDocUrl) { |
45 | 47 | List<Throwable> causalChain = Throwables.getCausalChain(e); |
46 | 48 | for (Throwable t : causalChain) { |
47 | 49 | if (t instanceof ProgramFailureException) { |
48 | 50 | // Avoid double wrap |
49 | 51 | return (ProgramFailureException) t; |
50 | 52 | } |
51 | 53 | if (t instanceof HttpResponseException) { |
52 | | - return getProgramFailureException((HttpResponseException) t); |
| 54 | + return getProgramFailureException((HttpResponseException) t, externalDocUrl); |
53 | 55 | } |
54 | 56 | } |
55 | 57 | // If no HttpResponseException found in the causal chain, return generic program failure exception |
56 | 58 | return ErrorUtils.getProgramFailureException(new ErrorCategory(ErrorCategory.ErrorCategoryEnum.PLUGIN), errorReason, |
57 | 59 | String.format("%s %s: %s", errorReason, e.getClass().getName(), e.getMessage()), errorType, dependency, e); |
58 | 60 | } |
59 | 61 |
|
60 | | - private static ProgramFailureException getProgramFailureException(HttpResponseException e) { |
| 62 | + private static ProgramFailureException getProgramFailureException(HttpResponseException e, String externalDocUrl) { |
61 | 63 | Integer statusCode = e.getStatusCode(); |
62 | 64 | ErrorUtils.ActionErrorPair pair = ErrorUtils.getActionErrorByStatusCode(statusCode); |
63 | 65 | String errorReason = |
64 | 66 | String.format("%s %s. %s", e.getStatusCode(), e.getStatusMessage(), pair.getCorrectiveAction()); |
65 | 67 | String errorMessage = e.getMessage(); |
66 | 68 | if (e instanceof GoogleJsonResponseException) { |
67 | 69 | errorMessage = getErrorMessage((GoogleJsonResponseException) e); |
68 | | - if (!Strings.isNullOrEmpty(GCPUtils.GCS_SUPPORTED_DOC_URL)) { |
| 70 | + if (!Strings.isNullOrEmpty(externalDocUrl)) { |
69 | 71 | if (!errorReason.endsWith(".")) { |
70 | 72 | errorReason = errorReason + "."; |
71 | 73 | } |
|
0 commit comments