package com.xero.api;

import java.util.HashMap;
import java.util.Map;

public class XeroApiException extends RuntimeException {

  private static final long serialVersionUID = 1L;

  private final int responseCode;
  public String message;
  public Map<String,String> messageMap = new HashMap<String,String>();;

  public XeroApiException(int responseCode) {
    super(responseCode + " response.");
    this.responseCode = responseCode;
  }

  public XeroApiException(int responseCode, String message) {
	  super(responseCode + " response: " + message);
	  this.responseCode = responseCode;
	  this.message = message;
  }
  
  public XeroApiException(int responseCode, Map<String,String> map) {
	  super(responseCode + "response");
	  this.responseCode = responseCode;
	  for (Map.Entry<String, String> entry : map.entrySet())
	  {
		  if(this.message == null) {
			  this.message = entry.getValue() + " - ";
		  } else {
			  this.message = this.message + entry.getValue() + " ";
		  }
	  }
	  this.messageMap = map;
  }
  
  public int getResponseCode() {
	  return responseCode;
  } 
  
  public String getMessage() {
	  return message;
  } 
  
  public Map<String,String> getMessages() {
	  return messageMap;
  } 
}

@@ -16,16 +16,53 @@
 o.api;%0A%0A
+import com.xero.model.ApiException;%0A%0A
 import j
@@ -160,16 +160,18 @@
 tion %7B%0A%0A
+  
   privat
@@ -214,16 +214,18 @@
  = 1L;%0A%0A
+  
   privat
@@ -252,22 +252,25 @@
 Code;%0A  
-public
+  private
  String 
@@ -280,22 +280,25 @@
 sage;%0A  
-public
+  private
  Map%3CStr
@@ -293,32 +293,33 @@
 vate Map%3CString,
+ 
 String%3E messageM
@@ -338,24 +338,25 @@
 hMap%3CString,
+ 
 String%3E();;%0A
@@ -353,19 +353,59 @@
 ring%3E();
+%0A    private ApiException apiException
 ;%0A%0A
+  
   public
@@ -442,16 +442,20 @@
 Code) %7B%0A
+    
     supe
@@ -490,16 +490,20 @@
 %22);%0A    
+   
+ 
 this.res
@@ -532,13 +532,17 @@
 de;%0A
+  
   %7D%0A%0A
+  
   pu
@@ -595,25 +595,30 @@
  message) %7B%0A
-%09
+      
   super(resp
@@ -654,17 +654,22 @@
 ssage);%0A
-%09
+      
   this.r
@@ -696,17 +696,22 @@
 seCode;%0A
-%09
+      
   this.m
@@ -726,29 +726,31 @@
  message;%0A  
-%7D
+  %7D%0A
 %0A  
-%0A
   public Xer
@@ -784,32 +784,33 @@
 ode, Map%3CString,
+ 
 String%3E map) %7B%0A%09
@@ -808,17 +808,22 @@
  map) %7B%0A
-%09
+      
   super(
@@ -850,17 +850,22 @@
 onse%22);%0A
-%09
+      
   this.r
@@ -892,17 +892,22 @@
 seCode;%0A
-%09
+      
   for (M
@@ -958,20 +958,26 @@
 t())
-%0A%09  %7B%0A%09%09
+ %7B%0A          
   if
+ 
 (thi
@@ -997,19 +997,30 @@
 null) %7B%0A
-%09%09%09
+              
   this.m
@@ -1054,18 +1054,26 @@
  %22 - %22;%0A
-%09%09
+          
   %7D else
@@ -1079,11 +1079,22 @@
 e %7B%0A
-%09%09%09
+              
   th
@@ -1149,52 +1149,341 @@
  %22;%0A
-%09%09  %7D%0A%09  %7D%0A%09  this.messageMap = map;%0A  %7D%0A  %0A
+            %7D%0A        %7D%0A        this.messageMap = map;%0A    %7D%0A%0A    public XeroApiException(int responseCode, String message, ApiException apiException) %7B%0A        super(responseCode + %22 response: %22 + message);%0A        this.responseCode = responseCode;%0A        this.message = message;%0A        this.apiException = apiException;%0A    %7D%0A%0A  
   pu
@@ -1507,25 +1507,30 @@
 nseCode() %7B%0A
-%09
+      
   return res
@@ -1538,30 +1538,31 @@
 onseCode;%0A  
-%7D
  
+ %7D%0A
 %0A  
-%0A
   public Str
@@ -1576,25 +1576,30 @@
 Message() %7B%0A
-%09
+      
   return mes
@@ -1608,16 +1608,17 @@
 ge;%0A
+  
   %7D
- 
+%0A
 %0A  
-%0A
   pu
@@ -1633,16 +1633,17 @@
 %3CString,
+ 
 String%3E 
@@ -1662,9 +1662,14 @@
 ) %7B%0A
-%09
+      
   re
@@ -1687,13 +1687,94 @@
 eMap;%0A  
-%7D
  
+ %7D%0A%0A    public ApiException getApiException() %7B%0A        return apiException;%0A    %7D
 %0A%7D%0A

update XeroApiException to wrap ApiException