// Path: src/main/java/dk/clanie/bitcoin/client/response/BitcoindErrorResponse.java
// @SuppressWarnings("serial")
// @RooJavaBean(settersByDefault = false)
// public class BitcoindErrorResponse extends BitcoindJsonRpcResponse<Object> {
// 
// }
// 
// Path: src/main/java/dk/clanie/bitcoin/exception/BitcoinException.java
// @SuppressWarnings("serial")
// public class BitcoinException extends AbstractRuntimeException {
// 
// 	private BitcoindErrorResponse errorResponse = null;
// 
// 
// 	protected BitcoinException(BitcoindErrorResponse errorResponse) {
// 		super(errorResponse.getError().getMessage());
// 		this.errorResponse = errorResponse;
// 	}
// 
// 
// 	public BitcoinException(Exception cause) {
// 		super(cause);
// 	}
// 	
// 
// 	public BitcoinException(String message, Exception cause) {
// 		super(message, cause);
// 	}
// 	
// 
// 	/**
// 	 * Gets the whole response received from bitcoind.
// 	 * 
// 	 * @return {@link BitcoindErrorResponse} - may be null.
// 	 */
// 	public BitcoindErrorResponse getErrorResponse() {
// 		return errorResponse;
// 	}
// 
// 
// 	/**
// 	 * Gets the error code received from bitcoind.
// 	 * 
// 	 * @return errorcode or null if no error code was received.
// 	 */
// 	public Integer getErrorCode() {
// 		if (errorResponse == null || errorResponse.getError() == null) return null;
// 		return errorResponse.getError().getCode();
// 	}
// 
// 
// 	@Override
// 	public String toString() {
// 		return ToStringBuilder.reflectionToString(this);
// 	}
// 
// 
// }
// 
// Path: src/main/java/dk/clanie/bitcoin/exception/client/BitcoinClientException.java
// @SuppressWarnings("serial")
// public class BitcoinClientException extends BitcoinException {
// 
// 	public BitcoinClientException(BitcoindErrorResponse errorResponse) {
// 		super(errorResponse);
// 	}
// 
// }
// 
// Path: src/main/java/dk/clanie/bitcoin/exception/client/MethodNotFoundException.java
// @SuppressWarnings("serial")
// public class MethodNotFoundException extends BitcoinClientException {
// 
// 
// 	public MethodNotFoundException(BitcoindErrorResponse errorResponse) {
// 		super(errorResponse);
// 	}
// 
// 	
// }
// 
// Path: src/main/java/dk/clanie/bitcoin/exception/server/BitcoinServerException.java
// @SuppressWarnings("serial")
// public class BitcoinServerException extends BitcoinException {
// 
// 	public BitcoinServerException(BitcoindErrorResponse errorResponse) {
// 		super(errorResponse);
// 	}
// 
// }
// 
// Path: src/main/java/dk/clanie/bitcoin/exception/server/InvalidAddressException.java
// @SuppressWarnings("serial")
// public class InvalidAddressException extends BitcoinServerException {
// 
// 
// 	public InvalidAddressException(BitcoindErrorResponse errorResponse) {
// 		super(errorResponse);
// 	}
// 
// 	
// }
// 
// Path: src/main/java/dk/clanie/bitcoin/exception/server/WalletEncryptionException.java
// @SuppressWarnings("serial")
// public class WalletEncryptionException extends BitcoinServerException {
// 
// 
// 	public WalletEncryptionException(BitcoindErrorResponse errorResponse) {
// 		super(errorResponse);
// 	}
// 
// 	
// }


import dk.clanie.bitcoin.client.response.BitcoindErrorResponse;
import dk.clanie.bitcoin.exception.BitcoinException;
import dk.clanie.bitcoin.exception.client.BitcoinClientException;
import dk.clanie.bitcoin.exception.client.MethodNotFoundException;
import dk.clanie.bitcoin.exception.server.BitcoinServerException;
import dk.clanie.bitcoin.exception.server.InvalidAddressException;
import dk.clanie.bitcoin.exception.server.WalletEncryptionException;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.util.FileCopyUtils;
import org.springframework.web.client.DefaultResponseErrorHandler;
import org.springframework.web.client.UnknownHttpStatusCodeException;
import com.fasterxml.jackson.databind.ObjectMapper;
				throw new MethodNotFoundException(errorResponse);
			default:
				throw new BitcoinClientException(errorResponse);
			}
		}
		default:
			try {
				super.handleError(response);
			} catch (Exception cause) {
				throw new BitcoinException(cause);
			}
		}
	}


	/**
	 * Parses the response body, deserializing it into an BitcoinJsonRpcErrorResponse object.
	 * <p>
	 * If parsing fails an BitcoinException containing the given HTTP error code is thrown.
	 * 
	 * @param response
	 * @param statusCode
	 * @return BitcoinJsonRpcErrorResponse
	 * @throws BitcoinException
	 */
	private BitcoindErrorResponse parseResponse(ClientHttpResponse response, HttpStatus statusCode) {
		String body = new String(getResponseBody(response), getCharset(response));
		try {
			return objectMapper.readValue(body, BitcoindErrorResponse.class);
		} catch (IOException ioe) {
// Path: src/main/java/dk/clanie/bitcoin/client/response/BitcoindErrorResponse.java
// @SuppressWarnings("serial")
// @RooJavaBean(settersByDefault = false)
// public class BitcoindErrorResponse extends BitcoindJsonRpcResponse<Object> {
// 
// }
// 
// Path: src/main/java/dk/clanie/bitcoin/exception/BitcoinException.java
// @SuppressWarnings("serial")
// public class BitcoinException extends AbstractRuntimeException {
// 
// 	private BitcoindErrorResponse errorResponse = null;
// 
// 
// 	protected BitcoinException(BitcoindErrorResponse errorResponse) {
// 		super(errorResponse.getError().getMessage());
// 		this.errorResponse = errorResponse;
// 	}
// 
// 
// 	public BitcoinException(Exception cause) {
// 		super(cause);
// 	}
// 	
// 
// 	public BitcoinException(String message, Exception cause) {
// 		super(message, cause);
// 	}
// 	
// 
// 	/**
// 	 * Gets the whole response received from bitcoind.
// 	 * 
// 	 * @return {@link BitcoindErrorResponse} - may be null.
// 	 */
// 	public BitcoindErrorResponse getErrorResponse() {
// 		return errorResponse;
// 	}
// 
// 
// 	/**
// 	 * Gets the error code received from bitcoind.
// 	 * 
// 	 * @return errorcode or null if no error code was received.
// 	 */
// 	public Integer getErrorCode() {
// 		if (errorResponse == null || errorResponse.getError() == null) return null;
// 		return errorResponse.getError().getCode();
// 	}
// 
// 
// 	@Override
// 	public String toString() {
// 		return ToStringBuilder.reflectionToString(this);
// 	}
// 
// 
// }
// 
// Path: src/main/java/dk/clanie/bitcoin/exception/client/BitcoinClientException.java
// @SuppressWarnings("serial")
// public class BitcoinClientException extends BitcoinException {
// 
// 	public BitcoinClientException(BitcoindErrorResponse errorResponse) {
// 		super(errorResponse);
// 	}
// 
// }
// 
// Path: src/main/java/dk/clanie/bitcoin/exception/client/MethodNotFoundException.java
// @SuppressWarnings("serial")
// public class MethodNotFoundException extends BitcoinClientException {
// 
// 
// 	public MethodNotFoundException(BitcoindErrorResponse errorResponse) {
// 		super(errorResponse);
// 	}
// 
// 	
// }
// 
// Path: src/main/java/dk/clanie/bitcoin/exception/server/BitcoinServerException.java
// @SuppressWarnings("serial")
// public class BitcoinServerException extends BitcoinException {
// 
// 	public BitcoinServerException(BitcoindErrorResponse errorResponse) {
// 		super(errorResponse);
// 	}
// 
// }
// 
// Path: src/main/java/dk/clanie/bitcoin/exception/server/InvalidAddressException.java
// @SuppressWarnings("serial")
// public class InvalidAddressException extends BitcoinServerException {
// 
// 
// 	public InvalidAddressException(BitcoindErrorResponse errorResponse) {
// 		super(errorResponse);
// 	}
// 
// 	
// }
// 
// Path: src/main/java/dk/clanie/bitcoin/exception/server/WalletEncryptionException.java
// @SuppressWarnings("serial")
// public class WalletEncryptionException extends BitcoinServerException {
// 
// 
// 	public WalletEncryptionException(BitcoindErrorResponse errorResponse) {
// 		super(errorResponse);
// 	}
// 
// 	
// }


// Path: src/main/java/dk/clanie/bitcoin/client/BitcoindJsonRpcErrorHandler.java
import dk.clanie.bitcoin.client.response.BitcoindErrorResponse;
import dk.clanie.bitcoin.exception.BitcoinException;
import dk.clanie.bitcoin.exception.client.BitcoinClientException;
import dk.clanie.bitcoin.exception.client.MethodNotFoundException;
import dk.clanie.bitcoin.exception.server.BitcoinServerException;
import dk.clanie.bitcoin.exception.server.InvalidAddressException;
import dk.clanie.bitcoin.exception.server.WalletEncryptionException;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.util.FileCopyUtils;
import org.springframework.web.client.DefaultResponseErrorHandler;
import org.springframework.web.client.UnknownHttpStatusCodeException;
import com.fasterxml.jackson.databind.ObjectMapper;

				throw new MethodNotFoundException(errorResponse);
			default:
				throw new BitcoinClientException(errorResponse);
			}
		}
		default:
			try {
				super.handleError(response);
			} catch (Exception cause) {
				throw new BitcoinException(cause);
			}
		}
	}


	/**
	 * Parses the response body, deserializing it into an BitcoinJsonRpcErrorResponse object.
	 * <p>
	 * If parsing fails an BitcoinException containing the given HTTP error code is thrown.
	 * 
	 * @param response
	 * @param statusCode
	 * @return BitcoinJsonRpcErrorResponse
	 * @throws BitcoinException
	 */
	private BitcoindErrorResponse parseResponse(ClientHttpResponse response, HttpStatus statusCode) {
		String body = new String(getResponseBody(response), getCharset(response));
		try {
			return objectMapper.readValue(body, BitcoindErrorResponse.class);
		} catch (IOException ioe) {
			throw new BitcoinException("Received an HTTP " + statusCode.value() + " " + statusCode.getReasonPhrase() + ". Response parsing failed.", ioe);