Skip to content

Commit

Permalink
Exposed messages of HttpExceptionInterface exceptions in JSON format
Browse files Browse the repository at this point in the history
  • Loading branch information
maryo committed May 18, 2018
1 parent d674955 commit b7d6257
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
5 changes: 4 additions & 1 deletion DependencyInjection/VanioApiExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ public function load(array $configs, ContainerBuilder $container): void
public function prepend(ContainerBuilder $container): void
{
$container->prependExtensionConfig('twig', [
'paths' => [sprintf('%s/../Resources/views', __DIR__) => 'NelmioApiDoc'],
'paths' => [
sprintf('%s/../Resources/views', __DIR__) => 'Twig',
sprintf('%s/../Resources/views/', __DIR__) => 'NelmioApiDoc',
],
]);
}

Expand Down
6 changes: 6 additions & 0 deletions Resources/views/Exception/error.json.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{% set data = exception.class is instance of('Symfony\\Component\\HttpKernel\\Exception\\HttpExceptionInterface')
? {code: status_code, message: status_text, errors: [exception.message]}
: {code: status_code, message: status_text}
%}

{{ data|serialize('json')|raw }}
6 changes: 6 additions & 0 deletions Resources/views/Exception/exception.json.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{% set data = exception.class is instance of('Symfony\\Component\\HttpKernel\\Exception\\HttpExceptionInterface')
? {code: status_code, message: status_text, errors: [exception.message], exception: exception.toArray()}
: {code: status_code, message: status_text, exception: exception.toArray()}
%}

{{ data|serialize('json')|raw }}

0 comments on commit b7d6257

Please sign in to comment.