Some other controller was causing problem and when I copied and paste some of the code, It started to work..
Thanks @ins0 for this suggestion.
문제
I want to return status code 403 from Module.php whenever authorization fails. I searched and found out that I need to attach listener to this file.
I am trying to do it this way. But I am getting 200 even if I am setting statusCode to 500. See the code below.
$em = $e->getApplication()->getEventManager();
// Authorize API call
$auth = $this->authorize($e->getApplication()->getServiceManager());
if(!auth)
{
$app = $e->getApplication();
$em->attach(MvcEvent::EVENT_ROUTE, function($e) use ($app) {
$response = $e->getResponse();
$response->setStatusCode(500);
$response->setContent(json_encode(array(
'message' => 'You are not authorized for this request',
)));
return $response;
}, PHP_INT_MAX);
}
해결책
Some other controller was causing problem and when I copied and paste some of the code, It started to work..
Thanks @ins0 for this suggestion.