Skip to content

Commit

Permalink
fix 500 response code on error pages
Browse files Browse the repository at this point in the history
  • Loading branch information
ahilles107 committed Sep 16, 2014
1 parent 912d77f commit ac283da
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion newscoop/application/configs/symfony/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ fos_rest:
codes:
'Newscoop\Exception\ResourcesConflictException': 409
'Newscoop\Exception\InvalidParametersException': 422
'Newscoop\Exception\ResourceIsEmptyException': 404
'Newscoop\Exception\ResourceIsEmptyException': 204
'Symfony\Component\Routing\Exception\ResourceNotFoundException': 404
'Doctrine\ORM\EntityNotFoundException': 404
'Symfony\Component\Form\Exception\InvalidArgumentException': 500
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ public function patchArticleAction(Request $request, $number, $language)

$em = $this->container->get('em');
$inputManipulator = $this->get('newscoop.input_manipulator');
$clean = array();

if (array_key_exists('authors', $params)) {
$authors = array();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ public function onResponse(FilterResponseEvent $event)
$response = $event->getResponse();
$request = $event->getRequest();

// HACK: revert exception status code to main request (i have no idea why it's chnaged to 500)
if (is_array($content = json_decode($response->getContent(), true))) {
if (array_key_exists('errors', $content)) {
$response->setStatusCode($content['errors'][0]['code'], $content['errors'][0]['message']);
}
}

if (!$this->container->hasParameter('newscoop.gimme.allow_origin')) {
return false;
}
Expand Down

0 comments on commit ac283da

Please sign in to comment.