-
Notifications
You must be signed in to change notification settings - Fork 177
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
How to respond with cusom HTTP status code in error handler #71
Comments
Create a custom Exception and inherit from ValidationException. Afterwards create and register your own ErrorHandler where you type-check for your own Exception and modify the passed response object accordingly. Something like this: <?php
namespace Acme\DemoBundle\ErrorHandler;
use Exception;
use Oneup\UploaderBundle\Uploader\ErrorHandler\ErrorHandlerInterface;
use Oneup\UploaderBundle\Uploader\Response\AbstractResponse;
use Your\Bundle\Upload\Exception\InvalidTypeException;
class CustomErrorHandler implements ErrorHandlerInterface
{
public function addException(AbstractResponse $response, Exception $exception)
{
if ($exception instanceof InvalidTypeException) {
$response->setStatusCode(415);
}
}
} Uhm. I don't think that it is necessary to inherit from ValidationException, but let me double check that. |
No need to inherit from ValidationException. Just create a custom one extending from |
When i try $response->setStatusCode(415); i'm getting this
|
You're right. |
To fix this issue, a lions share of the response handling has to be refactored, what implicates bc-breaks. Will be changed and implemented either in 1.1 or 2.0. |
@sheeep still nothing about this custom response? |
Is it possible to return custom HTTP status code to the client?
I want to respond with error code 415(Unsupported Media Type)
The text was updated successfully, but these errors were encountered: