public static ErrorItem toErrorItem(final String logMessage, final Throwable t) {
		
		// get a flat list of the throwable and the causal chain
		
		List<Throwable> throwables = Throwables.getCausalChain(t);

		// create and populate builders for all throwables
		
		List<ErrorItem.Builder> builders = new ArrayList<ErrorItem.Builder>(throwables.size());
		
		for (int i = 0; i < throwables.size(); ++i) {
			if (i == 0) {
				ErrorItem.Builder builder = toErrorItemBuilderWithoutCause(logMessage, throwables.get(i));
				builders.add(builder);
			} else {
				ErrorItem.Builder builder = toErrorItemBuilderWithoutCause(null, throwables.get(i));
				builders.add(builder);
			}
		}
		
		// attach child errors to their parent in reverse order
		
		for (int i = builders.size() - 1; 0 < i; --i) {
			ErrorItem.Builder parent = builders.get(i - 1);
			ErrorItem.Builder child = builders.get(i);
			
			parent.innerError(child.build());
		}
		
		// return the assembled original error
		
		return builders.get(0).build();
	}
public static ErrorItem toErrorItem ( final String logMessage , final Throwable t ) { List < Throwable > throwables = Throwables . getCausalChain ( t ) ; List < ErrorItem . Builder > builders = new ArrayList < ErrorItem . Builder > ( throwables . size ( ) ) ; for ( int i = 0 ; i < throwables . size ( ) ; ++ i ) { if ( i == 0 ) { ErrorItem . Builder builder = toErrorItemBuilderWithoutCause ( logMessage , throwables . get ( i ) ) ; builders . add ( builder ) ; } else { ErrorItem . Builder builder = toErrorItemBuilderWithoutCause ( null , throwables . get ( i ) ) ; builders . add ( builder ) ; } } for ( int i = builders . size ( ) - 1 ; 0 < i ; -- i ) { ErrorItem . Builder parent = builders . get ( i - 1 ) ; ErrorItem . Builder child = builders . get ( i ) ; parent . innerError ( child . build ( ) ) ; } return builders . get ( 0 ) . build ( ) ; }
Converts a Throwable to an ErrorItem
@param logMessage The log message (can be null)
@param t The Throwable to be converted
@return The ErrorItem