@param $statusCode
@param $responseBody

@return mixed

@throws CieloRequestException
186400
protected function readResponse($statusCode, $responseBody)
    {
        $unserialized = null;

        switch ($statusCode) {
            case 200:
            case 201:
                $unserialized = $this->unserialize($responseBody);
                break;
            case 400:
                $exception = null;
                $response  = json_decode($responseBody);

                foreach ($response as $error) {
                    $cieloError = new CieloError($error->Message, $error->Code);
                    $exception  = new CieloRequestException('Request Error', $statusCode, $exception);
                    $exception->setCieloError($cieloError);
                }

                throw $exception;
            case 404:
                throw new CieloRequestException('Resource not found', 404, null);
            default:
                throw new CieloRequestException('Unknown status', $statusCode);
        }

        return $unserialized;
    }
1086011
public function respond($content, $status = 200)
    {
        $transformed = $this->transform($content);

        return $this->responseFactory->json($transformed, $status);
    }
670841
public function error($errorCode = null, int $statusCode = null, $message = null):JsonResponse
    {
        if ($exception = config("responder.exceptions.$errorCode")) {
            if (class_exists($exception)) {
                throw new $exception();
            }
        }

        return $this->errorResponse->setError($errorCode, $message)->respond($statusCode);
    }
1022885
protected function redirect($location = null, $statusCode = 302)
    {
        return $this->response->redirect(url($location), true, $statusCode);
    }
370471
public function thenRespond($statusCode, $body)
    {
        $response = ResponseBuilder::create($statusCode)->andBody($body)->build()[1];

        return $this->expectation->setResponse($response);
    }
136686
public function convertResponseBodyToObject($responseBody, $contentTypeHeader)
    {
        try {
            $this->responseObject = $this->getKernel()->getContainer()->get('ezpublish_rest.input.dispatcher')->parse(
                new Message(
                    array('Content-Type' => $contentTypeHeader),
                    $responseBody
                )
            );
        } catch (\Exception $e) {
            // when errors/exceptions popup on form the response we need also to
            // test/verify them
            $this->responseObject = $e;
        }

        return $this->responseObject;
    }
558120
public function splitResponseHeaderAndBody(string $response, int $statusCode)
    {
        $headers = [];

        $split = strpos($response, "\r\n\r\n");
        $header = substr($response, 0, $split);
        $body = str_replace($header."\r\n\r\n", '', $response);

        foreach (explode("\r\n", $header) as $i => $strLine) {
            if (0 === $i) {
                $headers['http_code'] = $statusCode;
            } else {
                list($strKey, $varValue) = explode(': ', $strLine);
                $headers[$strKey] = $varValue;
            }
        }

        return [$headers, trim($body)];
    }
769713
public function onBeforeHTTPError($statusCode, $request)
    {
        if (Director::is_ajax()) {
            return;
        }
        $response = ErrorPage::response_for($statusCode);
        if ($response) {
            throw new HTTPResponse_Exception($response, $statusCode);
        }
    }
1019411
public function json($data, $statusCode=null)
    {
        // Set Status Code
        if ($statusCode) {
            $this->setStatusCode($statusCode);
        }
        
        $this->setFormat(Response::FORMAT_JSON);

        if (!is_null($data)) {
            $this->setData($data);
        }
        
        return $this->send();
    }
710316
public static function createFromArray($statusCode, array $data = [])
    {
        $response = new static($statusCode);

        if (isset($data['body']) && \is_array($data['body'])) {
            foreach ($data['body'] as $key => $bodyData) {
                $response->addBody(Body::createFromArray($key, $bodyData ?: []));
            }
        }

        if (isset($data['description'])) {
            $response->setDescription($data['description']);
        }

        if (isset($data['headers'])) {
            foreach ($data['headers'] as $key => $header) {
                $response->addHeader(NamedParameter::createFromArray($key, $header));
            }
        }

        return $response;
    }
282754
protected function processAction($action, FormInterface $form = null, $statusCode = Response::HTTP_NO_CONTENT)
    {
        $statusCode = $this->getParameterResolver()->resolveStatusCode($statusCode);

        $this->getRestEventDispatcher()->dispatch(
            RestEvents::ACTION,
            $event = new ActionEvent($this->resource, $action, $form, $statusCode)
        );

        $view = $event->getView();
        $statusCode = $view->getStatusCode();

        return $statusCode >= 300 && $statusCode < 400
            ? $this->handleView($view)
            : $this->processView($action, $view);
    }
975838
public function response($content, $statusCode = 200)
    {
        return response()
            ->json($this->convertContent($content))
            ->setStatusCode($statusCode);
    }
1096033
private function getDebugTraceResponse(\Exception $exception, $statusCode)
    {
        $request = $this->application->getRequest();
        $response = (new \Symfony\Component\Debug\ExceptionHandler())->createResponse($exception);
        $response->setStatusCode($statusCode);

        if (in_array('application/json', $request->getAcceptableContentTypes())) {
            $response = new JsonResponse($response->getContent(), $response->getStatusCode(), $response->headers->all());
        }

        return $response;
    }
1079338
public function getErrorResponse($errors, int $statusCode = self::HTTP_BAD_REQUEST, array $headers = [])
    {
        if (\is_iterable($errors) === true) {
            /** @var iterable $errors */
            $content = $this->getEncoder()->encodeErrors($errors);
        } else {
            \assert($errors instanceof ErrorInterface);
            $content = $this->getEncoder()->encodeError($errors);
        }

        return $this->createJsonApiResponse($content, $statusCode, $headers, true);
    }
427102
public function makeJsonReponse($status_code, $body)
    {
        $this->getResponse()->setBody(json_encode($body, JSON_UNESCAPED_SLASHES));
        $this->getResponse()->setStatusCode($status_code);
        $this->getResponse()->addHeader("Content-type", "application/json");

        return $this->getResponse();
    }
1023060
protected function _format($statusCode=null, $message=null, $body=false)
    {
        $format = [];
        // Status Code field is necessary
        $format['code'] = ($statusCode) 
            ?: $this->response->getStatusCode();
        // Message field
        if ($message) {
            $format['message'] = $message;
        }
        // Body field
        if ($body !== false) {
            $format['data'] = $body;
        }
        
        return $format;
    }
271029
private function validateJsonResponse($responseBody)
    {
        $data = json_decode($responseBody);

        if (json_last_error() !== JSON_ERROR_NONE) {
            throw new \Exception('Error decoding JSON.');
        }

        if (isset($data->error)) {
            throw new \Exception($data->error->error_message);
        }

        if (empty($data)) {
            throw new \Exception('No results found.');
        }

        return $responseBody;
    }