2013-02-16 2 views
3

누군가가이 문제를 해결할 수 있기를 바랍니다.예외 발생시 Rails에서 html이 아닌 json 렌더링

난 레일에 쓰고있는 웹 서비스 앱이있다. 서비스에 RocketPants, 승인에 Authority을 사용하고 있습니다.

Authority "that 's now allowed"예외 (Authority :: SecurityViolation)가 JSON이 아닌 HTML로 렌더링되는 예외 처리 문제가 발생했습니다.

나는 이야기를 this gistthis issue에 문서화했습니다.

내 ApiController 내에서 예외를 발생시켜 복제 할 수 있습니다 (raise "blah"). html 오류 페이지가 표시됩니다. 같은 this question 같은 rescue_from 같은 실패한 결과를 사용하여 시도했다.

어디서 왔는지 모르겠습니다. 누구든지 이것을 일으키는 Rails 예외 처리 스택에 무엇이 있는지 알고 있습니까? 어떤 도움을 주셔서 감사합니다.

답변

2

ApiController 클래스에서 이것을 시도 했습니까?

rescue_from StandardError, with: :render_unknown_error 


def render_unknown_error(error) 
    render(json: error.inspect, status: 500) 
end 
+2

[당신은 루비의 예외를 구출 절대로 해야하는 이유 (http://daniel.fone.net.nz/blog/2013/05/28/why-you-should-never-rescue-exception-in -ruby /) 이 기사에서는 StandardError 또는 더 구체적인 것을 잡아야 함을 제안합니다. – ChristopherJ

관련 문제