diff --git a/modules/rest-util/src/blaze/middleware/fhir/output.clj b/modules/rest-util/src/blaze/middleware/fhir/output.clj index 7fe018bce..cef4e914a 100644 --- a/modules/rest-util/src/blaze/middleware/fhir/output.clj +++ b/modules/rest-util/src/blaze/middleware/fhir/output.clj @@ -32,22 +32,22 @@ (with-open [_ (prom/timer generate-duration-seconds "json")] (fhir-spec/unform-json body))) -(defn- generate-xml** [body] +(defn- xml-byte-array [body] (let [out (ByteArrayOutputStream.)] (with-open [writer (io/writer out)] (xml/emit (fhir-spec/unform-xml body) writer)) (.toByteArray out))) -(defn- generate-xml* [body] +(defn- generate-xml* [response] (try - (generate-xml** body) + (update response :body xml-byte-array) (catch Throwable e - (generate-xml** (handler-util/operation-outcome (ba/anomaly e)))))) + (update response :body (constantly (xml-byte-array (handler-util/operation-outcome (ba/anomaly e)))))))) (defn- generate-xml [response] (log/trace "generate XML") (with-open [_ (prom/timer generate-duration-seconds "xml")] - (update response :body generate-xml*))) + (generate-xml* response))) (defn- encode-response-json [{:keys [body] :as response} content-type] (cond-> response body (-> (update :body generate-json)