Liking cljdoc? Tell your friends :D

com.blockether.anomaly.core

Cognitect Anomalies - standardized error categories.

Based on https://github.com/cognitect-labs/anomalies

Anomalies are maps with ::category key indicating the error type. These map to HTTP status codes:

CategoryHTTPDescription
::unavailable503Service temporarily unavailable, retry later
::interrupted500Operation was interrupted
::incorrect400Bad request, invalid input
::forbidden403Not authorized to perform this action
::unauthorized401Authentication required
::not-found404Resource not found
::conflict409Conflict with current state (e.g., duplicate)
::fault500Internal server error
::busy503Server is busy, retry later
::unsupported501Operation not supported

Usage: (throw! ::forbidden "You are not authorized to access this resource") (throw! ::not-found "Therapy plan not found" {:plan-id plan-id}) (throw! ::incorrect "Invalid email format" {:field :email})

Cognitect Anomalies - standardized error categories.

Based on https://github.com/cognitect-labs/anomalies

Anomalies are maps with ::category key indicating the error type.
These map to HTTP status codes:

| 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                        |

Usage:
(throw! ::forbidden "You are not authorized to access this resource")
(throw! ::not-found "Therapy plan not found" {:plan-id plan-id})
(throw! ::incorrect "Invalid email format" {:field :email})
raw docstring

anomalyclj/s

(anomaly category message)
(anomaly category message data)

Creates an anomaly map.

Params: category - Keyword. One of the anomaly categories. message - String. Human-readable error message. data - Map, optional. Additional context data.

Returns: Map. Anomaly with ::category, ::message, and any additional data.

Examples: (anomaly ::not-found "User not found") => {::category ::not-found, ::message "User not found"}

(anomaly ::forbidden "Access denied" {:user-id 123}) => {::category ::forbidden, ::message "Access denied", :user-id 123}

Creates an anomaly map.

Params:
`category` - Keyword. One of the anomaly categories.
`message` - String. Human-readable error message.
`data` - Map, optional. Additional context data.

Returns:
Map. Anomaly with ::category, ::message, and any additional data.

Examples:
(anomaly ::not-found "User not found")
=> {::category ::not-found, ::message "User not found"}

(anomaly ::forbidden "Access denied" {:user-id 123})
=> {::category ::forbidden, ::message "Access denied", :user-id 123}
sourceraw docstring

anomaly?clj/s

(anomaly? x)

Returns true if x is an anomaly map.

Params: x - Any. Value to check.

Returns: Boolean.

Returns true if x is an anomaly map.

Params:
`x` - Any. Value to check.

Returns:
Boolean.
sourceraw docstring

categoriesclj/s

Set of all valid anomaly categories.

Set of all valid anomaly categories.
sourceraw docstring

category->http-statusclj/s

Maps anomaly category to HTTP status code.

Maps anomaly category to HTTP status code.
sourceraw docstring

client-error?clj/s

(client-error? anomaly)

Returns true if anomaly represents a client error (4xx).

Params: anomaly - Map. Anomaly to check.

Returns: Boolean.

Returns true if anomaly represents a client error (4xx).

Params:
`anomaly` - Map. Anomaly to check.

Returns:
Boolean.
sourceraw docstring

conflict!clj/s

(conflict! message)
(conflict! message data)

Throws conflict (409) anomaly.

Params: message - String. Error message describing the conflict. data - Map, optional. Additional context.

Throws conflict (409) anomaly.

Params:
`message` - String. Error message describing the conflict.
`data` - Map, optional. Additional context.
sourceraw docstring

ex->anomalyclj/s

(ex->anomaly e)

Converts any exception to an anomaly.

If the exception already contains anomaly data, returns that. Otherwise, wraps it as a ::fault anomaly.

Params: e - Exception. The exception to convert.

Returns: Map. An anomaly map.

Converts any exception to an anomaly.

If the exception already contains anomaly data, returns that.
Otherwise, wraps it as a ::fault anomaly.

Params:
`e` - Exception. The exception to convert.

Returns:
Map. An anomaly map.
sourceraw docstring

ex-anomalyclj/s

(ex-anomaly e)

Extracts anomaly from an exception, if present.

Params: e - Exception. The exception to extract from.

Returns: Map or nil. The anomaly map if exception contains one, nil otherwise.

Extracts anomaly from an exception, if present.

Params:
`e` - Exception. The exception to extract from.

Returns:
Map or nil. The anomaly map if exception contains one, nil otherwise.
sourceraw docstring

fault!clj/s

(fault! message)
(fault! message data)

Throws fault (500) anomaly for internal errors.

Params: message - String. Error message (keep it generic for security). data - Map, optional. Additional context (for logging, not exposed to client).

Throws fault (500) anomaly for internal errors.

Params:
`message` - String. Error message (keep it generic for security).
`data` - Map, optional. Additional context (for logging, not exposed to client).
sourceraw docstring

forbidden!clj/s

(forbidden! message)
(forbidden! message data)

Throws forbidden (403) anomaly.

Params: message - String. Error message describing why access is denied. data - Map, optional. Additional context.

Throws forbidden (403) anomaly.

Params:
`message` - String. Error message describing why access is denied.
`data` - Map, optional. Additional context.
sourceraw docstring

http-statusclj/s

(http-status anomaly)

Returns HTTP status code for an anomaly.

Params: anomaly - Map. Anomaly with ::category key.

Returns: Integer. HTTP status code (defaults to 500 for unknown categories).

Returns HTTP status code for an anomaly.

Params:
`anomaly` - Map. Anomaly with ::category key.

Returns:
Integer. HTTP status code (defaults to 500 for unknown categories).
sourceraw docstring

incorrect!clj/s

(incorrect! message)
(incorrect! message data)

Throws incorrect (400) anomaly for validation errors.

Params: message - String. Error message describing what's invalid. data - Map, optional. Additional context (e.g., field names, validation errors).

Throws incorrect (400) anomaly for validation errors.

Params:
`message` - String. Error message describing what's invalid.
`data` - Map, optional. Additional context (e.g., field names, validation errors).
sourceraw docstring

not-found!clj/s

(not-found! message)
(not-found! message data)

Throws not-found (404) anomaly.

Params: message - String. Error message describing what wasn't found. data - Map, optional. Additional context.

Throws not-found (404) anomaly.

Params:
`message` - String. Error message describing what wasn't found.
`data` - Map, optional. Additional context.
sourceraw docstring

server-error?clj/s

(server-error? anomaly)

Returns true if anomaly represents a server error (5xx).

Params: anomaly - Map. Anomaly to check.

Returns: Boolean.

Returns true if anomaly represents a server error (5xx).

Params:
`anomaly` - Map. Anomaly to check.

Returns:
Boolean.
sourceraw docstring

throw!clj/s

(throw! category message)
(throw! category message data)

Throws an ex-info exception with anomaly data.

Params: category - Keyword. One of the anomaly categories. message - String. Human-readable error message. data - Map, optional. Additional context data.

Throws: ExceptionInfo with anomaly map as ex-data.

Examples: (throw! ::forbidden "You cannot access this resource") (throw! ::not-found "Patient not found" {:patient-id pid})

Throws an ex-info exception with anomaly data.

Params:
`category` - Keyword. One of the anomaly categories.
`message` - String. Human-readable error message.
`data` - Map, optional. Additional context data.

Throws:
ExceptionInfo with anomaly map as ex-data.

Examples:
(throw! ::forbidden "You cannot access this resource")
(throw! ::not-found "Patient not found" {:patient-id pid})
sourceraw docstring

unauthorized!clj/s

(unauthorized!)
(unauthorized! message)
(unauthorized! message data)

Throws unauthorized (401) anomaly.

Params: message - String, optional. Error message. Defaults to "Authentication required". data - Map, optional. Additional context.

Throws unauthorized (401) anomaly.

Params:
`message` - String, optional. Error message. Defaults to "Authentication required".
`data` - Map, optional. Additional context.
sourceraw docstring

unavailable!clj/s

(unavailable! message)
(unavailable! message data)

Throws unavailable (503) anomaly.

Params: message - String. Error message describing why service is unavailable. data - Map, optional. Additional context.

Throws unavailable (503) anomaly.

Params:
`message` - String. Error message describing why service is unavailable.
`data` - Map, optional. Additional context.
sourceraw docstring

unsupported!clj/s

(unsupported! message)
(unsupported! message data)

Throws unsupported (501) anomaly.

Params: message - String. Error message describing what's not supported. data - Map, optional. Additional context.

Throws unsupported (501) anomaly.

Params:
`message` - String. Error message describing what's not supported.
`data` - Map, optional. Additional context.
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close