FriendsOfSymfony / FOSRestBundle

This Bundle provides various tools to rapidly develop RESTful API's with Symfony
http://symfony.com/doc/master/bundles/FOSRestBundle/index.html
MIT License
2.79k stars 703 forks source link

Invalid HTTP code in fos_rest.exception.codes in default configuration #1952

Closed maykino closed 5 years ago

maykino commented 6 years ago

I'm trying to set up an API by following the examples from the documentation and default config from the symfony page:

https://symfony.com/doc/master/bundles/FOSRestBundle/configuration-reference.html

When trying to access the application I get the following errors right away:

Invalid HTTP code in fos_rest.exception.codes, see Symfony\Component\HttpFoundation\Response for all valid codes.

When removed the exception section there is another one:

The service "fos_rest.decoder_provider" has a dependency on a non-existent service "".

Since it's a default configuration I assumed that it would work out of the box. It's a hassle for a developer to now find out what each of the config option mean and provide the expected values.

xabbuh commented 6 years ago

Can you show the exact configuration that you used when running into both of these issues?

EliuFlorez commented 5 years ago

Hello! I have the same error:

// Clearing the cache for the dev environment with debug true

In FileLoader.php line 168:

  [Semantical Error] Couldn't find constant FOS\RestBundle\Util\Codes::HTTP_OK, method ArcaSolutions\ApiBundle\C
  ontroller\DefaultController::getHomeAction() in C:\xampp\htdocs\test-symfony\src\ArcaSolutions\ApiBundle/Resou
  rces/config/routing.yml (which is being imported from "C:\xampp\htdocs\test-symfony/app/config/routing.yml").
  Make sure there is a loader supporting the "rest" type.

In AnnotationException.php line 54:

  [Semantical Error] Couldn't find constant FOS\RestBundle\Util\Codes::HTTP_OK, method ArcaSolutions\ApiBundle\C
  ontroller\DefaultController::getHomeAction().

my configuration:

fos_rest:
    param_fetcher_listener: true
    body_listener: true
    format_listener:
        rules:
            - { path: ^/api, priorities: ['json', 'html', '*/*'], fallback_format: json, prefer_extension: true }
            - { path: ^/, stop: true }
    body_converter:
        enabled: true
        validate: true
    view:
        view_response_listener: 'force'
        formats:
            json: true
            xml: false
        templating_formats:
            html: true
    exception:
        codes:
            'Symfony\Component\Routing\Exception\ResourceNotFoundException': 404
            'Doctrine\ORM\OptimisticLockException': HTTP_CONFLICT
        messages:
            'Symfony\Component\Routing\Exception\ResourceNotFoundException': true
            'Symfony\Component\HttpKernel\Exception\HttpException': true
        enabled: true
    access_denied_listener:
        json: true
    disable_csrf_role: ROLE_API

fos_error

xabbuh commented 5 years ago

Can you show the code of your DefaultController class?

EliuFlorez commented 5 years ago

¿Puedes mostrar el código de tu DefaultControllerclase? My controller's code

fos_error_code

xabbuh commented 5 years ago

The error is triggered by the usage of the @ApiDoc annotation. Which version of FOSRestBundle do you use?

EliuFlorez commented 5 years ago

El error se desencadena por el uso de la @ApiDocanotación. ¿Qué versión de FOSRestBundle usas?

-version "friendsofsymfony/jsrouting-bundle": "^2.2", "friendsofsymfony/oauth-server-bundle": "^1.6", "friendsofsymfony/rest-bundle": "^2.4", "nelmio/api-doc-bundle": "^2.13",

xabbuh commented 5 years ago

The FOS\RestBundle\Util\Codes class doesn't exist in FOSRestBundle 2.x anymore. You will need to use another class that provides HTTP status code constants.

EliuFlorez commented 5 years ago

ok ready now I have this error on request:

Fatal error: Uncaught exception 'Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException' with message 'You have requested a non-existent service "request". Did you mean one of these: "fos_rest.request.param_fetcher", "fos_rest.request.param_fetcher.reader", "monolog.logger.request", "nelmio_api_doc.event_listener.request", "request_stack", "router.request_context", "validate_request_listener", "argument_resolver.request", "argument_resolver.request_attribute", "security.request_matcher.x1icpav", "security.request_matcher.zfhj2lw"?'

please help.

xabbuh commented 5 years ago

I am sorry, but this is far beyond what we can support in the issue tracker. The request service has been removed in Symfony 3.0. I suggest to seek for help on the Symfony Slack team or on StackOverflow (see Https://symfony.com/support).

Tobion commented 5 years ago

Closing as not actionable.

max4ever commented 4 years ago

I had to remove these red lines image Even though symfony documentation gives that bit https://symfony.com/doc/master/bundles/FOSRestBundle/configuration-reference.html