2011-07-28 3 views
8

DeadlineExceededError를 잡아서 처리하고 싶기 때문에 App Engine에서 기본적으로 throw하는 표준 "서버 오류"페이지가 표시되지 않습니다.어떻게 글로벌 DeadlineExceededError 핸들러를 설정할 수 있습니까?

요청 처리기에 DeadlineExceededErrors가 not caught when overriding handle_exception 인 것을 알고 있습니다. 이미 처리했습니다.

error_handlers: 
    - error_code: timeout 
    file: timeout.html 

을 ...하지만 그 또한 내가 뭔가를 잘못하고 있어요 않는 한, DeadlineExceededErrors을 잡으려고하지 않는 것 :

나는 custom error_handlers app.yaml configuration과 같이 사용, 실패 지금까지 시도했습니다.

class MainPage(webapp.RequestHandler): 
    def get(self): 
     try: 
      # Do stuff... 
     except DeadlineExceededError: 
      # Many Whelps! Handle it! 

을 ...하지만 난 내 응용 프로그램에서 모든 단일 요청 처리기에 이것을 추가하지 싶습니다 :

은 내가 특정 요청 핸들러 내부 DeadlineExceededErrors을 잡기 위해 다음과 같은 패턴을 사용할 수 있음을 알고 있습니다.

나는 어떻게이 애매한 빠는 사람을 세계적으로 붙잡을 수 있습니까?

답변

3

가능한 한 가지 해결책은 webapp2를 사용하는 것입니다. webapp2는 원래의 webapp에 비해 훨씬 유용한 프레임 워크이며 많은 도움이됩니다. 다음과 같이 webapp2, 당신은의 handle_500 방법의 예외를 처리 할 수 ​​

def BaseHandler(webapp2.RequestHandler): 
    def handle_500(request, response, exception): 
     if isinstance(exception, DeadlineExceededError): 
      response.write('Deadline exceeded!') 
     else: 
      response.write('A server error occurred!') 

     logging.exception(exception) 
     response.set_status(500) 
+0

이 webapp2에서 500 상태 코드를 처리하는 오류 핸들러를 설정할 수 있습니다 - 대부분 캐치되지 않는 예외에 사용됩니다. 거기에 어떤 유형의 예외인지 확인하고 이에 따라 처리합니다. if isinstance (exception, DeadlineExceededError) : ... 문서는 여기에 있습니다. http://webapp-improved.appspot.com/guide/exceptions.html#exceptions-in- the-wsgi-app – moraes

+0

나는 그것을 실제로 몰랐다. 예, 오류 처리를 배치하는 것이 더 적절한 장소가 될 것입니다. –

+1

이것이 내가 제안한 것입니다. 오류 리디렉션을 보내지 마십시오. 동일한 URL의 오류 페이지를 제공하십시오. –

관련 문제