Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LRS-61 Remove Error Interceptor #71

Merged
merged 11 commits into from
Dec 13, 2021
4 changes: 3 additions & 1 deletion src/dev/mem_lrs/service.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
(:require [io.pedestal.http :as http]
[com.yetanalytics.lrs.impl.memory :as lrs-impl :refer [new-lrs]]
[com.yetanalytics.lrs.pedestal.routes :refer [build]]
[com.yetanalytics.lrs.pedestal.interceptor :as i]
#?(:cljs [com.yetanalytics.node-chain-provider :as provider])))

(defn new-routes [lrs]
(build {:lrs lrs}))
(build {:lrs lrs
:wrap-interceptors [i/error-interceptor]}))
Comment on lines +9 to +10
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

demonstrates plugging in your own


;; Tabular routes + default LRS
(def default-lrs
Expand Down
35 changes: 18 additions & 17 deletions src/main/com/yetanalytics/lrs/pedestal/interceptor.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -243,22 +243,24 @@
;; Log all unhandled/bubbled errors
(log/error :msg "Unhandled LRS Error"
:exception ex)
(let [err-type
(cond
(nil? ex) {:name "unknown"}
(exi? ex) (let [{:keys [type exception-type]} (ex-data ex)
type-k (or exception-type
type
:unknown/unknown)
[tns tname] ((juxt namespace name) type-k)]
(merge (when tns {:ns tns})
{:name tname}))
(error? ex) {:name (str (type ex))}
(string? ex) {:name ex}
:else {:name "unknown"})]
(assoc ctx :response {:status 500
:body {:error
{:type err-type}}})))))}))
(assoc ctx
:response
{:status 500
:body {:error
(merge
{:message "Unhandled LRS Error"}
(cond
(nil? ex) {:type "unknown"}
(exi? ex) (let [{:keys [type exception-type]} (ex-data ex)
type-k (or exception-type
type
:unknown/unknown)
[tns tname] ((juxt namespace name) type-k)]
(merge (when tns {:ns tns})
{:type tname}))
(error? ex) {:type (str (type ex))}
(string? ex) {:type ex}
:else {:type "unknown"}))}}))))}))

;; Time Requests

Expand Down Expand Up @@ -420,7 +422,6 @@
:cljs (body-params/body-params))]
[x-forwarded-for-interceptor
http/json-body
error-interceptor
body-params
xapi/alternate-request-syntax-interceptor
set-xapi-version-interceptor
Expand Down
50 changes: 30 additions & 20 deletions src/main/com/yetanalytics/lrs/pedestal/routes.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -85,22 +85,31 @@
:enter (fn health-fn [ctx]
(assoc ctx :response {:status 200 :body ""}))}))

(defn build [{:keys [lrs path-prefix]
:or {path-prefix "/xapi"}}]
(defn build [{:keys [lrs
path-prefix
wrap-interceptors]
:or {path-prefix "/xapi"
wrap-interceptors []}}]
kelvinqian00 marked this conversation as resolved.
Show resolved Hide resolved
(let [lrs-i (i/lrs-interceptor lrs)
global-interceptors-no-auth (conj i/common-interceptors
lrs-i)
global-interceptors (conj i/common-interceptors
lrs-i
auth-i/lrs-authenticate
auth-i/lrs-authorize)
protected-interceptors (into global-interceptors
i/xapi-protected-interceptors)
document-interceptors (into (conj i/doc-interceptors-base
global-interceptors-no-auth (into wrap-interceptors
(conj i/common-interceptors
lrs-i))
global-interceptors (into wrap-interceptors
(conj i/common-interceptors
lrs-i
auth-i/lrs-authenticate
auth-i/lrs-authorize)
i/xapi-protected-interceptors)]
auth-i/lrs-authorize))
protected-interceptors (into wrap-interceptors
(concat
global-interceptors
i/xapi-protected-interceptors))
document-interceptors (into wrap-interceptors
(concat
(conj i/doc-interceptors-base
lrs-i
auth-i/lrs-authenticate
auth-i/lrs-authorize)
i/xapi-protected-interceptors))]
(into #{;; health check
["/health"
:get (conj global-interceptors-no-auth
Expand All @@ -116,13 +125,14 @@

;; xapi statements
[(format "%s/statements" path-prefix)
:get (into [auth-i/www-authenticate]
(concat
protected-interceptors
[statements-i/set-consistent-through
(xapi-i/params-interceptor
:xapi.statements.GET.request/params)
statements/handle-get]))]
:get (into
[auth-i/www-authenticate]
(concat
protected-interceptors
[statements-i/set-consistent-through
(xapi-i/params-interceptor
:xapi.statements.GET.request/params)
statements/handle-get]))]
[(format "%s/statements" path-prefix)
:head (conj protected-interceptors
statements-i/set-consistent-through
Expand Down