Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Blockether/anomaly

Repository files navigation

Anomaly

Blockether anomalies - standardized error categories based on Cognitect anomalies.

Installation

Add the following dependency to your deps.edn:

{:deps {com.blockether/anomaly {:mvn/version "1.0.1"}}}

Usage

(require '[com.blockether.anomaly.core :as anomaly])
;; Throw standardized errors
(anomaly/not-found! "User not found" {:user-id 123})
(anomaly/forbidden! "Access denied")
(anomaly/incorrect! "Invalid email format" {:field :email})
;; Create anomaly maps without throwing
(anomaly/anomaly ::anomaly/not-found "Resource missing" {:id 456})
;; Check HTTP status
(anomaly/http-status {::anomaly/category ::anomaly/forbidden}) ;; => 403
;; Predicates
(anomaly/anomaly? some-map)
(anomaly/client-error? anomaly-map)
(anomaly/server-error? anomaly-map)

Anomaly Categories

Category HTTP Description
::unavailable 503 Service temporarily unavailable, retry later
::interrupted 500 Operation was interrupted
::incorrect 400 Bad request, invalid input
::forbidden 403 Not authorized to perform this action
::unauthorized 401 Authentication required
::not-found 404 Resource not found
::conflict 409 Conflict with current state (e.g., duplicate)
::fault 500 Internal server error
::busy 503 Server is busy, retry later
::unsupported 501 Operation not supported

About

Standardised error categories based on Cognitect anomalies

Topics

Resources

License

Stars

Watchers

Forks

Packages

Contributors

AltStyle によって変換されたページ (->オリジナル) /