Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable exception stack trace #2390

Open
dcr31000 opened this issue Jun 22, 2023 · 1 comment
Open

Disable exception stack trace #2390

dcr31000 opened this issue Jun 22, 2023 · 1 comment

Comments

@dcr31000
Copy link

I have a Symfony v6 application with FosRestBundle.

When I go to an endpoint which throw an exception, I got a page with the full error and the stack trace. Also in production mode.

Capture d’écran 2023-06-21 à 10 18 57

The kernel is configured like this:

$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);

And this is the configuration of fos_rest I use:

fos_rest:
  body_listener: true
  body_converter:
    enabled: true
    validate: true
    validation_errors_argument: violations
  view:
    formats: { json: true, xml: false, rss: false }
    view_response_listener: true
  serializer:
    serialize_null: true
  format_listener:
    rules:
      - { path: '^/api', priorities: ['json'], fallback_format: 'json', prefer_extension: true }
      - { path: '^/publicapi', priorities: ['json'], fallback_format: 'json', prefer_extension: true }
      - { path: '^/', priorities: ['html'], fallback_format: 'html' }
  param_fetcher_listener: force
  exception:
    enabled: true
    codes:
      'Symfony\Component\Security\Core\Exception\BadCredentialsException': 401
      'Symfony\Component\Security\Core\Exception\InvalidArgumentException': 400

I do not found how to disable the stack trace in production environment.

Thanks for your help

@shakaran
Copy link

shakaran commented Aug 4, 2023

@dcr31000 Maybe do you need to add under exception.codes:

'Symfony\Component\Routing\Exception\ResourceNotFoundException': 404

Useful doc: https://github.com/FriendsOfSymfony/FOSRestBundle/blob/3.x/Resources/doc/4-exception-controller-support.rst

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants