2013-07-22 7 views
2

여기 받침대에 포수 인터셉터의 내 첫 번째 시도이다 :간단한 오류 인터셉터를 작성하는 방법은 무엇입니까?

(definterceptorfn catcher [] 
    (interceptor 
    :error (fn [context error] 
      {:status 500 
      :body (->> error .toString (hash-map :error) json/write-str) 
      :headers {"Content-type" "application/json"}}))) 

내 코드 (/ 1 0)를 추가하여 테스트 할 수로서, 함수가 호출되는 않지만, 클라이언트가 빈을 얻는다 응답을 맵에 표시하지 않고 상태 200으로 응답합니다. 왜 그런지 궁금합니다. 문맥이 필요한 때

(defroutes routes 
    [[["/api" 
    ^:interceptors [(body-params/body-params) (catcher) bootstrap/html-body] 
    ... 

답변

2

Tim Ewald explained, 나는이 응답 맵을 반환했다 : 변수 내 경로에 공상 아무것도 없다

.

(definterceptorfn catcher [] 
    (interceptor 
    :error (fn [context error] 
      (assoc context :response 
      {:status 500 
      :body (->> error .toString (hash-map :error) json/write-str) 
      :headers {"Content-type" "application/json"}})))) 
으로 고정