/*
 * Copyright 2011 Splunk, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"): you may
 * not use this file except in compliance with the License. You may obtain
 * a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */

package com.splunk.http;

import com.splunk.atom.Xml; // UNODNE: Ugly cross package reference

import org.w3c.dom.Document;
import org.w3c.dom.NodeList;

public class HTTPException extends RuntimeException {
    private int status;

    HTTPException(int status, String message) {
        super(message);
        this.status = status;
    }

    static HTTPException create(ResponseMessage response) {
        int status = response.getStatus();

        // Attempt to read the error detail from the error response content.
        String detail = null;
        try {
            Document document = Xml.parse(response.getContent());
            NodeList msgs = document.getElementsByTagName("msg");
            if (msgs.getLength() > 0)
                detail = msgs.item(0).getTextContent();
        }
        catch (Exception e) {} // Couldn't get detail

        String message = String.format("HTTP %d", status);  

        if (detail != null)
            message = message + " -- " + detail;

        return new HTTPException(status, message);
    }

    public int getStatus() {
        return this.status;
    }
}


@@ -821,16 +821,67 @@
  status;
+%0A    private String detail; // Error message detail
 %0A%0A    HT
@@ -918,16 +918,31 @@
  message
+, String detail
 ) %7B%0A    
@@ -987,24 +987,54 @@
 s = status;%0A
+        this.detail = detail;%0A
     %7D%0A%0A    s
@@ -1233,20 +1233,18 @@
 etail = 
-null
+%22%22
 ;%0A      
@@ -1726,25 +1726,95 @@
 tus, message
-)
+, detail);%0A    %7D%0A%0A    public String getDetail() %7B%0A        return detail
 ;%0A    %7D%0A%0A   
@@ -1854,21 +1854,16 @@
  return 
-this.
 status;%0A

Add property for accessing error message detail separately from overall error message.