Пример #1
0
 public function testGetResponseErrorCase()
 {
     $apiResponse = new ApiResponse();
     $apiResponse->setError('error1');
     $apiResponse->setStatusCode(Response::HTTP_INTERNAL_SERVER_ERROR);
     $response = $apiResponse->getResponse();
     $this->assertSame('{"error":"error1"}', $response->getContent());
     $this->assertSame(Response::HTTP_INTERNAL_SERVER_ERROR, $response->getStatusCode());
 }
Пример #2
0
 /**
  * @param GetResponseForExceptionEvent $event
  * @throws \Exception
  */
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     $exception = $event->getException();
     $message = sprintf('Exception: %s with code: %s', $exception->getMessage(), $exception->getCode());
     $response = new ApiResponse();
     $response->setError($message);
     $response->setStatusCode(Response::HTTP_INTERNAL_SERVER_ERROR);
     $event->setResponse($response->getResponse());
 }