HerdErrorInformationExceptionHandler { @SuppressWarnings({"unchecked", "rawtypes"}) public boolean isReportableError(Throwable exception) { boolean isReportable = true; if (exception instanceof Exception) { Method method = resolver.resolveMethod((Exception) exception); if ((method != null) && (ErrorInformation.class.isAssignableFrom(method.getReturnType()))) { List<Object> parameterValues = new ArrayList<>(); Class[] parameterTypes = method.getParameterTypes(); for (Class clazz : parameterTypes) { if (clazz.isAssignableFrom(exception.getClass())) { parameterValues.add(exception); } else { parameterValues.add(null); } } try { ErrorInformation errorInformation = (ErrorInformation) method.invoke(this, parameterValues.toArray()); if (errorInformation.getStatusCode() != HttpStatus.INTERNAL_SERVER_ERROR.value()) { isReportable = false; } } catch (IllegalAccessException | InvocationTargetException ex) { logError("Unable to invoke method \"" + method.getDeclaringClass().getName() + "." + method.getName() + "\" so couldn't determine if exception is reportable. Defaulting to true.", ex); } } } return isReportable; }  @ExceptionHandler(value = AccessDeniedException.class) @ResponseStatus(HttpStatus.FORBIDDEN) @ResponseBody ErrorInformation handleAccessDeniedException(Exception exception); @ExceptionHandler(value = ActivitiException.class) @ResponseBody ErrorInformation handleActivitiException(Exception exception, HttpServletResponse response); @ExceptionHandler(value = {IllegalArgumentException.class, HttpMessageNotReadableException.class, MissingServletRequestParameterException.class, TypeMismatchException.class, UnsupportedEncodingException.class}) @ResponseStatus(HttpStatus.BAD_REQUEST) @ResponseBody ErrorInformation handleBadRequestException(Exception exception); @ExceptionHandler(value = {AlreadyExistsException.class, ObjectAlreadyExistsException.class, OptimisticLockException.class}) @ResponseStatus(HttpStatus.CONFLICT) @ResponseBody ErrorInformation handleConflictException(Exception exception); @ExceptionHandler(value = Exception.class) @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) @ResponseBody ErrorInformation handleInternalServerErrorException(Exception exception); @ExceptionHandler(value = {org.hibernate.ObjectNotFoundException.class, ObjectNotFoundException.class}) @ResponseStatus(HttpStatus.NOT_FOUND) @ResponseBody ErrorInformation handleNotFoundException(RuntimeException exception); @ExceptionHandler(value = MethodNotAllowedException.class) @ResponseStatus(HttpStatus.METHOD_NOT_ALLOWED) @ResponseBody ErrorInformation handleOperationNotAllowedException(RuntimeException exception); @ExceptionHandler(value = {JpaSystemException.class, PersistenceException.class}) @ResponseBody ErrorInformation handlePersistenceException(Exception exception, HttpServletResponse response); boolean isLoggingEnabled(); void setLoggingEnabled(boolean loggingEnabled); @SuppressWarnings({"unchecked", "rawtypes"}) boolean isReportableError(Throwable exception); static final int ORACLE_DATA_TOO_LARGE_ERROR_CODE; static final int ORACLE_LONG_DATA_IN_LONG_COLUMN_ERROR_CODE; static final String ORACLE_SQL_STATE_CODE_ERROR; static final String POSTGRES_SQL_STATE_CODE_FOREIGN_KEY_VIOLATION; static final String POSTGRES_SQL_STATE_CODE_UNIQUE_INDEX_OR_PRIMARY_KEY_VIOLATION; static final String POSTGRES_SQL_STATE_CODE_TRUNCATION_ERROR; }
@Test public void testIsReportableErrorThrowable() throws Exception { assertTrue(exceptionHandler.isReportableError(new Throwable(MESSAGE))); }