2016-10-18 4 views
0

사용자 지정 JSON 오류 메시지를 렌더링하고 싶습니다. 나는 다음과 같은 한 UrlMappings 클래스 내부컨트롤러의 Grails 오류 처리

class ErrorController { 

    static responseFormats = ['json'] 

    def notAuthorized() { 
     render([error: "You are not authorized to access ${request.getRequestURL()} on this server.", 
       path: request.getRequestURI()] as JSON) 
    } 
} 

:

{"error":"You are not authorized to access http://localhost:8080/error on this server.", 
"path":"/error"} 
:

"401"(controller: 'error', action: 'notAuthorized') 

모든 나는 다음과 같은 오류 메시지가 GET http://localhost/path는 사실을 제외하고 확실히 작동 나는 다음과 같은 컨트롤러를 생성

request 개체의 URI/URL이 요청에 지정된 URI/URL을 가리 키지 않습니다. 올바른 URI/URL을 얻을 수있는 방법이 있습니까?

답변

2

내가 원하는 것은 request.forwardURI이라고 생각합니다. 그러면 오류가 발생한 요청이 제공됩니다.

관련 문제