    (router handler {}))
   ([handler options]
    (fn [context]
-     (let [body (:body context)
-           data (.getBytes ^TypedData (:body context))
-           content-type (get-content-type body)
-           frame (exc/try-on (decode data content-type))]
-       (if (and (exc/success? frame) (not (nil? @frame)))
-         (dispatch handler context content-type @frame)
-         (http/unsupported-mediatype (str (m/extract frame))))))))
+     (try
+       (let [content-type (get-content-type context)
+             data (get-incoming-data context)
+             frame (decode data content-type)]
+         (dispatch handler context content-type frame))
+       (catch Exception e
+         (http/unsupported-mediatype (str e)))))))

  "A postal protocol implementation on top of http."
  (:require [catacumba.serializers :as sz]
            [catacumba.http :as http]
            [manifold.deferred :as md]
            [promissum.core :as p]
            [cats.core :as m]
            [cats.monad.exception :as exc])
  (:import ratpack.http.TypedData
           java.util.concurrent.CompletableFuture))


  [data _]
  (sz/encode data :transit+json))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Implementation
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defn- get-content-type
  [context]
  (let [^TypedData body (:body context)
        ^String content-type (.. body getContentType getType)]
    (when content-type
      (keyword (.toLowerCase content-type)))))

