リクエストの形式に応じてエラー 500 が発生したときに、Grails でさまざまなレスポンスを提供しようとしています。
ErrorController を作成し、URLMappings で使用していますが、正しい要求形式を取得していません。
def handle() {
withFormat {
html {
response.status = 500
render(view:'/errors/serverError')
}
json {
response.setContentType "application/json; charset=utf-8"
response.status = 500
ApiResponse apiResponse = new ApiResponse(
meta: new ApiMeta(
code: 500,
errorType: "Whatever",
msgs: ["${request.exception}"]
)
)
render apiResponse as JSON
}
}
}
応答は常に html です。同じ結果で「request.withFormat」でも試しました。
ここで何が欠けていますか?