2016-10-18 10 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だと思います。それはあなたにエラーを引き起こした要求を与えるはずです。