Skip to content

Commit

Permalink
refactor generate-xml* and generate-xml**
Browse files Browse the repository at this point in the history
  • Loading branch information
allentiak committed Nov 25, 2024
1 parent 34b032d commit 4612f6c
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions modules/rest-util/src/blaze/middleware/fhir/output.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 4612f6c

Please sign in to comment.