   json web token/signature."
   [claims pkey & [{:keys [alg exp nbf iat headers] :or {alg :hs256 headers {}}}]]
   {:pre [(map? claims)]}
-  (let [header (encode-header alg headers)
-        claims (encode-claims claims exp nbf iat)
-        signature (calculate-signature pkey alg header claims)]
-    (either/right (str/join "." [header claims signature]))))
+  (exc/try-on
+   (let [header (encode-header alg headers)
+         claims (encode-claims claims exp nbf iat)
+         signature (calculate-signature {:key pkey
+                                         :alg alg
+                                         :header header
+                                         :claims claims})]
+     (str/join "." [header claims signature]))))
 
 (defn decode
   "Given a signed message, verify it and return

            [buddy.core.sign.rsapss :as rsapss]
            [buddy.core.sign.rsapkcs15 :as rsapkcs]
            [buddy.core.sign.ecdsa :as ecdsa]
            [buddy.sign.util :refer [to-timestamp timestamp] :as util]
            [clojure.string :as str]
            [cheshire.core :as json]
            [cats.monad.either :as either])
  (:import clojure.lang.Keyword))

(def ^{:doc "List of supported signing algorithms"

  [data]
  (into {} (map (fn [[key val]]
                  (if (satisfies? util/ITimestamp val)
                    [key (util/to-timestamp val)]
                    [key val])) data)))

(defn normalize-nil-claims
