Permalink
Browse files

Allow to set arbitrary status code for Exception strategy

  • Loading branch information...
bakura10 committed Jan 13, 2013
1 parent af27c95 commit 8c3673e0a98105ce0921560e1a51affde47e2ab0
@@ -158,9 +158,10 @@ public function prepareExceptionViewModel(MvcEvent $e)
$response = $e->getResponse();
if (!$response) {
$response = new HttpResponse();
+ $response->setStatusCode(500);
$e->setResponse($response);
}
- $response->setStatusCode(500);
+ $response->setStatusCode($response->getStatusCode());
break;
}
}
@@ -169,4 +169,25 @@ public function testDetachesListeners()
$listeners = $events->getListeners(MvcEvent::EVENT_DISPATCH_ERROR);
$this->assertEquals(0, count($listeners));
}
+
+ public function testReuseResponseStatusCodeIfItExists()
+ {
+ $event = new MvcEvent();
+ $response = new Response();
+ $response->setStatusCode(401);
+ $event->setResponse($response);
+ $this->strategy->prepareExceptionViewModel($event);
+ $response = $event->getResponse();
+ if (null !== $response) {
+ $this->assertEquals(401, $response->getStatusCode());
+ }
+ $model = $event->getResult();
+ if (null !== $model) {
+ $variables = $model->getVariables();
+ $this->assertArrayNotHasKey('message', $variables);
+ $this->assertArrayNotHasKey('exception', $variables);
+ $this->assertArrayNotHasKey('display_exceptions', $variables);
+ $this->assertNotEquals('error', $model->getTemplate());
+ }
+ }
}

0 comments on commit 8c3673e

Please sign in to comment.