Liking cljdoc? Tell your friends :D

Capturing Errors

You can provide an event to be dispatched when an error occurs during transition by calling re-flow.events/set-error-handler. A no-op handler is used by default. The event will be dispatched with an error appended to it. The error does not have a standard form since it may be dispatched from a custom interceptor, but errors generated by the interceptors within re-flow have the form [error-name desc], where error-name is a namespaced keyword and desc is a string describing the error.

An error may occur when a db-spec or transition-spec are not satisfied or if a state for the specified transition data is not found.

Following is a short example that prints error messages to the browser console. (Normally, you would use an effect to perform a side effect, but it is included in the event in the sample for simplicity.)

(ns error-handling-example.core
  (:require [reagent.core :as reagent]
            [re-frame.core :as re-frame]
            [re-flow.core :as re-flow]
            [re-flow.events]))

(re-frame/reg-event-db :on-flow-error
  (fn [db [_ev msg]]
    (js/console.log (str msg))
    db))

(def self-flow
  (re-flow/flow [{:name :self
                  :transition {:self :self}}]
                {:start :self}))

(defn main-panel []
  [:button {:on-click #(re-flow/transition :invalid-value)} "Trigger error!"])

(defn mount-root []
  (re-frame/clear-subscription-cache!)
  (reagent/render [main-panel]
                  (.getElementById js/document "app")))

(defn ^:export init []
  (re-flow.events/set-error-handler :on-flow-error)
  (re-flow/start self-flow)
  (mount-root))

When you press the "Trigger error" button, the following error message will be written to the console:

[:re-flow.error/transition "state not found for transition :invalid-value"]

Can you improve this documentation?Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close