2014-04-29 4 views
0

PlayF 1.2.7 인터셉터에 문제가 있습니다. @Before 주석이있는 컨트롤러 AuthCtl이 있습니다. 그리고 @With (AuthCtl.class)를 사용하는 다른 컨트롤러 클래스 AlarmCtl. 나는 checkAuthorization 방법에 예외를 던지는있을 때 Playframework 1.2.7 인터셉터

public class AuthCtl extends Controller { 

    public static final String KMK_AUTH_TOKEN = "KMK_AUTH_TOKEN"; 
    public static final String KMK_USER_ID = "KMK_USER_ID"; 


    @Before 
    static void checkAuthorization() throws KomekException { 
     if (request.cookies.containsKey(AuthCtl.KMK_AUTH_TOKEN) && 
       request.cookies.containsKey(AuthCtl.KMK_USER_ID)) { 
      //Something 
     } else { 
      throw new UnauthorizedException(); 
     } 
    } 

    @Catch 
    static void handleExceptions(Throwable t) { 
     response.status = ((KomekException)t).getErrorCode(); 
     response.accessControl("*"); 
     response.contentType = "application/json"; 
     renderText(t.toString()); 
    } 
} 


@With(AuthCtl.class) 
public class AlarmCtl extends Controller { 
    //Something 
} 

그래서 내 handleExceptions 방법을 차단하지 않습니다. 뭐가 문제 야?

답변

0

잡으려는 예외 유형을 지정해야합니다. 사용 모두를 잡을 일반에 대한 루트 예외 클래스 (더러운의 종류)

@Catch(KomekException.class) 
static void handleExceptions(Throwable t) { 
    response.status = ((KomekException)t).getErrorCode(); 
    response.accessControl("*"); 
    response.contentType = "application/json"; 
    renderText(t.toString()); 
} 

을 또는 :

@Catch(Exception.class) 
static void handleExceptions(Throwable t) { 
    response.status = ((KomekException)t).getErrorCode(); 
    response.accessControl("*"); 
    response.contentType = "application/json"; 
    renderText(t.toString()); 
} 

따라서 귀하의 경우는 다음과 같이 작성 될 필요가있다