Skip to content

Commit

Permalink
Merge pull request #79 from fluree/feature/use-error-formatter
Browse files Browse the repository at this point in the history
Use error formatting fn in query error coercion
  • Loading branch information
mpoffald authored Oct 27, 2023
2 parents 4171b12 + 73b18ce commit cf66c7a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
5 changes: 3 additions & 2 deletions deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
org.slf4j/slf4j-api {:mvn/version "2.0.9"}
metosin/reitit {:mvn/version "0.6.0"}
metosin/muuntaja {:mvn/version "0.6.8"}
metosin/malli {:mvn/version "0.13.0"}
metosin/malli {:git/url "https://github.com/metosin/malli.git"
:git/sha "5211aca498ff7b022c36de4ca713990f5e731a9c" }
ring-cors/ring-cors {:mvn/version "0.1.13"}
com.fluree/db {:git/url "https://github.com/fluree/db.git"
:git/sha "a9cbf41c355ac7415239fa37e6eb3790faad15b0"}}
:git/sha "310e71e0175302660f8312f1410173e2b63c66a3"}}

:aliases
{:dev
Expand Down
13 changes: 12 additions & 1 deletion src/fluree/http_api/components/http.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
[donut.system :as ds]
[fluree.db.query.fql.syntax :as fql]
[fluree.db.query.history :as fqh]
[fluree.db.validation :as v]
[fluree.db.json-ld.credential :as cred]
[fluree.db.json-ld.transact :as transact]
[fluree.db.util.log :as log]
Expand Down Expand Up @@ -73,7 +74,7 @@

(def FqlQuery (m/schema [:and
[:map-of :keyword :any]
(fql/query-schema [[:from LedgerAlias]])]
(fql/query-schema [])]
{:registry fql/registry}))

(def SparqlQuery (m/schema :string))
Expand Down Expand Up @@ -130,12 +131,21 @@
{:port (ds/ref [:env :http/server :port])
:join? false}}})

(def query-coercer
(rcm/create
{:strip-extra-keys false
:error-keys #{}
:encode-error (fn [explained]
{:error :db/invalid-query
:message (v/format-explained-errors explained nil)})}))

(def query-endpoint
{:summary "Endpoint for submitting queries"
:parameters {:body QueryRequestBody}
:responses {200 {:body QueryResponse}
400 {:body ErrorResponse}
500 {:body ErrorResponse}}
:coercion ^:replace query-coercer
:handler #'ledger/query})

(def history-endpoint
Expand All @@ -144,6 +154,7 @@
:responses {200 {:body HistoryQueryResponse}
400 {:body ErrorResponse}
500 {:body ErrorResponse}}
:coercion ^:replace query-coercer
:handler #'ledger/history})

(defn wrap-assoc-conn
Expand Down
2 changes: 1 addition & 1 deletion src/fluree/http_api/handlers/ledger.clj
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
did (assoc :did did)))
query* (if opts (assoc query :opts opts) query)]
{:status 200
:body (deref! (fluree/from-query conn query* {:format format}))}))
:body (deref! (fluree/query-connection conn query* {:format format}))}))

(defhandler history
[{:keys [fluree/conn content-type credential/did] {{ledger :from :as query} :body} :parameters}]
Expand Down

0 comments on commit cf66c7a

Please sign in to comment.