/** * Helper method for translating the given set of constraint violations set into a set of {@link ApiError} objects * by calling {@link #convertValidationErrorToApiError(ConstraintViolation)} on each one. */ protected SortedApiErrorSet convertValidationErrorsToApiErrors(List<ConstraintViolation<Object>> validationErrors) { SortedApiErrorSet apiErrors = new SortedApiErrorSet(); for (ConstraintViolation<Object> validationError : validationErrors) { apiErrors.add(convertValidationErrorToApiError(validationError)); } return apiErrors; }
@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(); }
/** * Returns the default list of {@link ApiExceptionHandlerListener}s that should work for most applications without * any further additions. */ public static List<ApiExceptionHandlerListener> defaultHandlerListeners(ProjectApiErrors projectApiErrors, ApiExceptionHandlerUtils utils) { return Arrays.asList(new GenericApiExceptionHandlerListener(), new ServersideValidationErrorHandlerListener(projectApiErrors, utils), new ClientDataValidationErrorHandlerListener(projectApiErrors, utils), new DownstreamNetworkExceptionHandlerListener(projectApiErrors), new BackstopperRiposteFrameworkErrorHandlerListener(projectApiErrors)); }
return convertValidationErrorsToApiErrors(ex.getViolations());
/** * @return The basic set of handler listeners that are appropriate for most JAX-RS applications. */ public static List<ApiExceptionHandlerListener> defaultApiExceptionHandlerListeners( ProjectApiErrors projectApiErrors, ApiExceptionHandlerUtils utils ) { return Arrays.asList( new GenericApiExceptionHandlerListener(), new ServersideValidationErrorHandlerListener(projectApiErrors, utils), new ClientDataValidationErrorHandlerListener(projectApiErrors, utils), new DownstreamNetworkExceptionHandlerListener(projectApiErrors), new JaxRsWebApplicationExceptionHandlerListener(projectApiErrors, utils)); }