Skip to content

Provide an easy way to override the status code dynamically #7903

@VincentLanglet

Description

@VincentLanglet

Description
Maybe this already exists and I don't find it but I'd have a POST route I'd like to return a respond with either a 200 or a 202 status code.
Currently this does not seems to be supported since the Operation::getStatusCode is a single integer.

Does it exists @soyuka ? Are you ok with such feature ?
What do you recommend for this ?

I'm not sure but if the status is coming for here

$status = $this->getStatus($request, $operation, $context);

It could be easy to change here
$status = $operation->getStatus();

into

$status = $request->attributes('_api_response_status', $operation->getStatus());

Example

class MyProcessor
{
      public function process()
      {
           if ($count > 25) {
                      $request->attributes->set('_api_response_status', 202);
                      $dispatcher->publish(...);
           } else {
                      // default status will be 200
                      $service->execute(...);
           }

           return $output;
      }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions