@Override public ApiExceptionHandlerListenerResult shouldHandleException(Throwable ex) { // We only care about ClientDataValidationErrors. if (ex instanceof ClientDataValidationError) { List<Pair<String, String>> extraDetailsForLogging = new ArrayList<>(); SortedApiErrorSet apiErrors = processClientDataValidationError( (ClientDataValidationError)ex, extraDetailsForLogging ); return ApiExceptionHandlerListenerResult.handleResponse(apiErrors, extraDetailsForLogging); } // Not a ClientDataValidationError. Ignore. return ApiExceptionHandlerListenerResult.ignoreResponse(); }
@Override public ApiExceptionHandlerListenerResult shouldHandleException(Throwable ex) { ServersideValidationError sve = null; // Try to get the ServersideValidationError if (ex instanceof ServersideValidationError) sve = (ServersideValidationError)ex; else if ((ex instanceof DownstreamRequestOrResponseBodyFailedValidationException) && (ex.getCause() instanceof ServersideValidationError)) { sve = (ServersideValidationError) ex.getCause(); } if (sve != null) { // Process the ServersideValidationError to add logging details and get the appropriate SortedApiErrorSet. List<Pair<String, String>> extraDetailsForLogging = new ArrayList<>(); SortedApiErrorSet apiErrors = processServersideValidationError(sve, extraDetailsForLogging); return ApiExceptionHandlerListenerResult.handleResponse(apiErrors, extraDetailsForLogging); } // Not an exception we know how to handle - ignore it. return ApiExceptionHandlerListenerResult.ignoreResponse(); }
/** * @return An {@link ApiExceptionHandlerListenerResult} indicating whether we should handle the given exception. * If {@link ApiExceptionHandlerListenerResult#shouldHandleResponse} is true then * {@link ApiExceptionHandlerListenerResult#errors} and * {@link ApiExceptionHandlerListenerResult#extraDetailsForLogging} must be filled in appropriately and * ready for passing in to * {@link #doHandleApiException(SortedApiErrorSet, List, List, Throwable, RequestInfoForLogging)}. If it is * false then the given exception will be ignored by this class (and should therefore ultimately be handled * by this project's implementation of {@link UnhandledExceptionHandlerBase}). */ protected ApiExceptionHandlerListenerResult shouldHandleApiException(Throwable ex) { // The original exception might be a "wrapper" exception. If so, unwrap it so we can send the core exception // through our list of listeners. Throwable coreEx = unwrapAndFindCoreException(ex); // Run through each listener looking for one that wants to handle the core exception. for (ApiExceptionHandlerListener listener : apiExceptionHandlerListenerList) { ApiExceptionHandlerListenerResult result = listener.shouldHandleException(coreEx); if (result.shouldHandleResponse) return result; } // We didn't have any handler that wanted to deal with this exception, so return an "ignore it" response. return ApiExceptionHandlerListenerResult.ignoreResponse(); }
@Override public ApiExceptionHandlerListenerResult shouldHandleException(Throwable ex) { // We only care about ApiExceptions. if (!(ex instanceof ApiException)) return ApiExceptionHandlerListenerResult.ignoreResponse(); ApiException apiException = ((ApiException)ex); // Add all the ApiErrors from the exception. SortedApiErrorSet errors = new SortedApiErrorSet(); errors.addAll(apiException.getApiErrors()); // Add all the extra details for logging from the exception. List<Pair<String, String>> messages = new ArrayList<>(); messages.addAll(apiException.getExtraDetailsForLogging()); // Add all the extra response headers from the exception. List<Pair<String, List<String>>> headers = new ArrayList<>(); headers.addAll(apiException.getExtraResponseHeaders()); // Include the ApiException's message as a logged key/value pair. if (StringUtils.isNotBlank(ex.getMessage())) messages.add(Pair.of("api_exception_message", ex.getMessage())); return ApiExceptionHandlerListenerResult.handleResponse(errors, messages, headers); } }
@Override public ApiExceptionHandlerListenerResult shouldHandleException(Throwable ex) { SortedApiErrorSet handledErrors = null; List<Pair<String, String>> extraDetailsForLogging = new ArrayList<>(); // Look for exceptions we're supposed to handle. if (isTemporaryProblem(ex, extraDetailsForLogging)) { handledErrors = singletonSortedSetOf(projectApiErrors.getTemporaryServiceProblemApiError()); } else if (ex instanceof ServerHttpStatusCodeException) { handledErrors = processServerHttpStatusCodeException( (ServerHttpStatusCodeException) ex, extraDetailsForLogging ); } else if (ex instanceof ServerUnknownHttpStatusCodeException) { handledErrors = processServerUnknownHttpStatusCodeException( (ServerUnknownHttpStatusCodeException) ex, extraDetailsForLogging ); } if (handledErrors != null) return ApiExceptionHandlerListenerResult.handleResponse(handledErrors, extraDetailsForLogging); // Not an exception we care about - ignore it. return ApiExceptionHandlerListenerResult.ignoreResponse(); }
result = ApiExceptionHandlerListenerResult.ignoreResponse();
return ApiExceptionHandlerListenerResult.ignoreResponse();