Helper functions for returning unified responses.
Helper functions for returning unified responses.
(as-error ctx)
(as-error type ctx)
Returns wrapped unified error
result with the given value.
Returns wrapped unified `error` result with the given value.
(as-success ctx)
(as-success type ctx)
Returns wrapped unified success
result with the given value.
Returns wrapped unified `success` result with the given value.
Default unified error
type.
Default unified `error` type.
Default unified success
type.
Default unified `success` type.
(error? v)
Returns true
when the given value is unified error
result. Otherwise false
.
Returns `true` when the given value is unified `error` result. Otherwise `false`.
(get-error v)
Returns unified error
result.
Returns unified `error` result.
(get-error-context v)
Returns context
of unified error
result.
Returns `context` of unified `error` result.
(get-error-type v)
Returns type
of unified error
result.
Returns `type` of unified `error` result.
(get-success v)
Returns unified success
result.
Returns unified `success` result.
(get-success-context v)
Returns context
of unified success
result.
Returns `context` of unified `success` result.
(get-success-type v)
Returns type
of unified success
result.
Returns `type` of unified `success` result.
(if-error bindings then)
(if-error bindings then else & oldform)
Works the same as if-success
, but with inverted logic.
Works the same as `if-success`, but with inverted logic.
(if-success bindings then)
(if-success bindings then else & oldform)
Works the same as if-some
or if-let
, but checks for unified success
result.
And returns pair with result as [:type :ctx].
Where :type is keyword and :ctx is any value.
Examples: (if-success [[type ctx] (db/get-user-by-email "john@doe.com")] (println :success type ctx) (println :error type ctx))
If user exists: => :success :ok {:user/id 1, :user/email "john@doe.com"} If user not exists => :error :not-found {:user/login "john@doe.com"} If caught exception: => :error :fault #error{:cause class java.lang.Long cannot be cast to class java.lang.CharSequence ...}
Works the same as `if-some` or `if-let`, but checks for unified `success` result. And returns pair with result as [:type :ctx]. Where :type is keyword and :ctx is any value. Examples: (if-success [[type ctx] (db/get-user-by-email "john@doe.com")] (println :success type ctx) (println :error type ctx)) If user exists: => :success :ok {:user/id 1, :user/email "john@doe.com"} If user not exists => :error :not-found {:user/login "john@doe.com"} If caught exception: => :error :fault #error{:cause class java.lang.Long cannot be cast to class java.lang.CharSequence ...}
(success? v)
Returns true
when the given value is unified success
result. Otherwise false
.
Returns `true` when the given value is unified `success` result. Otherwise `false`.
(when-error bindings & then)
Works the same as if-error
, but without else
branch.
Works the same as `if-error`, but without `else` branch.
(when-success bindings & then)
Works the same as if-success
, but without else
branch.
Works the same as `if-success`, but without `else` branch.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close