Liking cljdoc? Tell your friends :D

aws-api-failjure

Clojars Project

A library for dealing with anomalies when using aws-api. Provides helpers to turn anomalies into Clojure ExceptionInfo objects or into failjure Failure objects.

Install

Add to deps.edn:

io.staticweb/aws-api-failjure {:mvn/version "1.0.0"}

Or add to project.clj:

[io.staticweb/aws-api-failjure "1.0.0"]

Usage

Create clients as you normally would using aws-api. This example requires you to have a com.cognitect.aws/s3 dependency, but you can replace {:api :s3} with any other API that you have the dependency for.

(require '[aws-api-failjure :as aaf]
         '[cognitect.aws.client.api :as aws]
         '[failjure.core :as f])

(def client (aws/client {:api :s3}))

failjure

Use aws-api-failjure/invoke in place of aws-api's invoke to turn unsuccessful operations into Failure objects for use with failjure:

(f/if-let-ok? [r (aaf/invoke client ,,,op-map,,,)]
  r
  (prn "Request failed:" (f/message r)))

throwing-invoke

Use aws-api-failjure/throwing-invoke to turn unsuccessful operations into clojure.lang.ExceptionInfo objects:

(try
  (aaf/throwing-invoke client ,,,op-map,,,)
  (catch clojure.lang.ExceptionInfo e
    (prn "Request failed:" (:message (ex-data e)))))

(ex-data e) is a map containing the keys :client :message :op-map :result.

aws/invoke

You can also use aws-api's invoke normally, check for the presence of :cognitect.anomalies/category, and use aws-api-failjure/message to retrieve a human-readable error message.

(let [result (aws/invoke client ,,,op-map,,,)]
  (if (:cognitect.anomalies/category result)
    (prn "Request failed:" (aaf/message result))
    result))

Can you improve this documentation? These fine people already did:
John Shaffer & staticweb-io
Edit on GitHub

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

× close