Skip to content
This repository has been archived by the owner on Dec 7, 2024. It is now read-only.

[Clojure] Improve Error Handling #16

Open
naomijub opened this issue May 22, 2023 · 1 comment
Open

[Clojure] Improve Error Handling #16

naomijub opened this issue May 22, 2023 · 1 comment
Labels
bug Something isn't working Clojure This issue is clojure related enhancement New feature or request help wanted Extra attention is needed

Comments

@naomijub
Copy link
Owner

naomijub commented May 22, 2023

As a User
I want to have proper error handling in the Clojure gRPC side
Currently we rely on Protojure grpc interceptor to handle errors
So we need to implement an interceptor to handle gXTDB errors as well as XDTB transaction errors

@naomijub naomijub changed the title Improve Error Handling [Clojure] Improve Error Handling May 22, 2023
@naomijub naomijub added bug Something isn't working enhancement New feature or request help wanted Extra attention is needed labels May 22, 2023
@naomijub
Copy link
Owner Author

naomijub commented May 22, 2023

;; protojure/pedestal/interceptor/grpc.clj
(def error-interceptor
  (err/error-dispatch
   [ctx ex]

   [{:exception-type ::status/error}]
   (let [{:keys [code msg]} (ex-data ex)]
     (err-status ctx code msg))

   :else
   (err-status ctx (grpc.status/get-code :internal) (ex-message ex))))

;; protojure/pedestal/routes.clj
(defn ->tablesyntax
  "Generates routes in [Table Syntax](http://pedestal.io/reference/table-syntax) format"
  [{:keys [rpc-metadata interceptors callback-context] :as options}]
  (for [{:keys [pkg service method method-fn] :as rpc} rpc-metadata]
    (let [fqs (str pkg "." service)
          name (keyword fqs (str method "-handler"))
          handler (handler name (partial method-fn callback-context))]
      [(str "/" fqs "/" method)
       :post (-> (consv grpc/error-interceptor interceptors)
                 (conj grpc.web/proxy
                       (grpc/route-interceptor rpc)
                       handler))
       :route-name name])))

;; gxtdb.service.clj
(defn grpc-routes [xtdb-node] (reduce conj routes (proutes/->tablesyntax {:rpc-metadata api/rpc-metadata :interceptors common-interceptors :callback-context (GrpcAPI. xtdb-node)})))

@naomijub naomijub added the Clojure This issue is clojure related label Jun 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working Clojure This issue is clojure related enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant