 (def internal-error-ring-response
   {:status 500 :body {:errors ["An Internal Error has occurred."]} :content-type :json})
 
+(defn- response-type-body
+  "Returns the response content-type and body for the given errors and format"
+  [errors xml-format?]
+  (let [content-type (if xml-format? "application/xml" "application/json")
+        body (if xml-format?
+               (x/indent-str
+                 (x/element :errors {}
+                            (for [err errors]
+                              (x/element :error {} err))))
+               {:errors errors})]
+    [content-type body]))
+
 (defn exception-handler
   "A ring exception handler that will handle errors thrown by the cmr.common.services.errors
   functions."

      (catch clojure.lang.ExceptionInfo e
        (let [data (ex-data e)]
          (if (:type data)
            (let [{:keys [type errors]} data
                  status-code (type->http-status-code type)]
              {:status status-code
               :headers {"Content-Type" "application/json"}
               :body {:errors errors}})
            (do
              (error e)
              internal-error-ring-response))))

(ns cmr.common.api.errors
  (:require [cmr.common.log :refer [error]]
            [clojure.data.xml :as x]))

(def type->http-status-code
  {:not-found 404
