Converts a problem to a JSON HTTP Response object, provided.

@param ApiProblem $problem
The problem to convert.

@return ResponseInterface
The appropriate response object.
977434
public function toJsonResponse(ApiProblem $problem) : ResponseInterface
    {
        $response = $this->toResponse($problem);

        $body = $response->getBody();
        $body->write($problem->asJson($this->pretty));
        $body->rewind();

        return $response
            ->withHeader('Content-Type', ApiProblem::CONTENT_TYPE_JSON)
            ->withBody($body);
    }
874380
public function jsonToInterface($data)
    {
        $parser = new PHPFHIRResponseParser();
        $fhirAppointment = $parser->parse($data);
        if ($fhirAppointment instanceof FHIRAppointment) {
            return $this->modelToInterface($fhirAppointment);
        } else {
            // Error, the Resource does not match, expecting a Appointment,
            // // but got something else.
            echo 'Error, the Resource does not match, expecting a Appointment';
        }
    }
665223
private function withError(ResponseInterface $response, $throwable)
    {
        $detail = 'Internal Server Error';
        $extensions = [];

        if ($this->displayErrorDetails) {
            $throwables = $this->unpackThrowables($throwable);
            $extensions['error_details'] = $this->formatStacktraceForExceptions($throwables);

            $detail = $throwable->getMessage();
        }

        $problem = new HTTPProblem(500, $detail, $extensions);
        return $this->renderProblem($response, $this->renderer, $problem);
    }
457223
public function changes(string $issue)
    {
        return new Changes($this->getHttpClient(), $this->username, $this->repo, $issue);
    }
1019653
protected function errorCheckResponse(ResponseInterface $response)
    {
        $body = $response->getBody();

        if ($response->getStatusCode() >= 400) {
            throw new HttpException($response);
        }

        $responseObject = @json_decode($this->streamToString($body));
        if (!isset($responseObject)) {
            throw new Exception('JSON returned is not valid', $response);
        }

        if (isset($responseObject->error)) {
            throw new Exception($responseObject->error, $response);
        }
    }
67434
public function serverError(\Throwable $exception, ServerRequestInterface $request) : ResponseInterface
    {
        $this->exception = $exception;

        $acceptType = $request->getHeader('Accept');
        if (is_array($acceptType) && count($acceptType) > 0 && strpos($acceptType[0], 'json') !== false) {
            return new JsonResponse(['error' => ['message' => $exception->getMessage(), 'type' => 'Exception', 'trace' => $this->debugMode ? $exception->getTraceAsString() : '']], 500);
        }

        if ($this->contentFor500) {
            $this->contentBlock->addHtmlElement($this->contentFor500);
        } else {
            $this->contentBlock->addFile(__DIR__ . '/../../../../views/500.php', $this);
        }

        return HtmlResponse::create($this->template, 500);
    }
311169
private function validateResponse(ResponseInterface $response)
    {
        if ($response->getStatusCode() !== 200) {
            $responseData = json_decode((string) $response->getBody(), true);
            $code = isset($responseData['error']['code']) ? $responseData['error']['code'] : 0;
            $message = isset($responseData['error']['message']) ? $responseData['error']['message'] : $response->getReasonPhrase();

            throw new ApiException($message, $code, $responseData);
        }
    }
448187
public final function withMethod($method): RequestInterface
   {
       if (!is_string($method)
        || !($toUpperMethod = strtoupper((string) $method))
        || $toUpperMethod !== $this->parseMethod($method)) {
           throw new InvalidArgumentException(
               "Can't get instance for method: " . $method . " not supported");
       }
       return $this->with("method", $toUpperMethod);
   }
536931
public function error($exception)
    {
        $response = new Response();

        // Set the default error response
        $response->setContent('There has been a problem serving this request.');
        $response->headers->set('content-type', 'text/html');
        $response->setStatusCode(Response::HTTP_INTERNAL_SERVER_ERROR);

        // Execute the user defined error callback
        if (is_callable($this->error)) {
            $response = call_user_func($this->error, $response, $exception);
        }

        // Send the response
        $response->send();
    }
644081
protected function handleException()
    {
        $this->handleNotJsonException($this->getResponse());

        if (false === $this->getInstapushClient()->isHandleException()) {
            return $this
                ->getInstapushClient()
                ->getTransformer()
                ->transform($this->getResponse(), ApiError::class);
        }

        $content = \json_decode($this->getResponse()->getBody()->__toString(), true);

        $message = true === isset($content['msg']) ? $content['msg'] : 'An unexpected error occurred : '.$content;

        throw new ApiException($message, $this->getRequest(), $this->getResponse());
    }
619872
public function toResponse($request): JsonResponse
    {
        return response()->json([
            'success' => $this->result,
            'message' => ($this->result)
                ? trans('comments::messages.send_success')
                : trans('comments::messages.send_fail'),
        ]);
    }
1012168
public function jsonToInterface($data)
    {
        $parser = new \PHPFHIRGenerated\PHPFHIRResponseParser();
        $fhirPatient = $parser->parse($data);
        if ($fhirPatient instanceof FHIRPatient) {
            return $this->modelToInterface($fhirPatient);
        } else {
            // Error, the Resource does not match, expecting a Patient,
            // // but got something else.
            abort(403, 'Error, the Resource does not match, expecting a Patient, but got "' . typeOf($fhirPatient). '"');
        }
    }
1120940
private function processResponse(ResponseInterface $response)
    {
        if($response->getStatusCode() != 200){
            throw new YouHostingException("The API returned with a non-successful error code: ".$response->getStatusCode());
        }

        $json = $response->json();

        if(!empty($json['error'])){
            throw new YouHostingException($json['error']['message'], $json['error']['code']);
        }

        return $json['result'];
    }
883468
public function badRequest(BadRequestException $exception, ServerRequestInterface $request) : ResponseInterface
    {
        $this->exception = $exception;

        $acceptType = $request->getHeader('Accept');
        if (is_array($acceptType) && count($acceptType) > 0 && strpos($acceptType[0], 'json') !== false) {
            return new JsonResponse(['error' => ['message' => 'Bad request sent', 'type' => 'bad_request']], 400);
        }

        if ($this->contentFor400) {
            $this->contentBlock = $this->contentFor400;
        } else {
            $this->contentBlock->addFile(__DIR__ . '/../../../../views/400.php', $this);
        }

        return HtmlResponse::create($this->template, 400);
    }
55847
public function comments(string $issue)
    {
        return new Comments($this->getHttpClient(), $this->username, $this->repo, $issue);
    }
381979
protected function convert(\Exception $exception)
    {
        $statusCode = $exception instanceof HttpExceptionInterface ? $exception->getStatusCode() : Response::HTTP_INTERNAL_SERVER_ERROR;
        $file = Path::makeRelative($exception->getFile(), $this->pathResolver->resolve('root'));

        $response = new JsonResponse([
            'success'   => false,
            'code'      => $statusCode,
            'error'     => [
                'type'    => $this->getErrorType($exception),
                'file'    => $file,
                'line'    => $exception->getLine(),
                'message' => $exception->getMessage(),
            ],
        ]);
        $response->setStatusCode($statusCode);

        return $response;
    }
1298494
public function jsonToInterface($data)
    {
        $parser = new \PHPFHIRGenerated\PHPFHIRResponseParser();
        $fhirPharmacy= $parser->parse($data);
        if ($fhirPharmacy instanceof FHIROrganization) {
            return $this->modelToInterface($fhirPharmacy);
        } else {
            // Error, the Resource does not match, expecting a Patient,
            // // but got something else.
            abort(403, 'Error, the Resource does not match, expecting a Patient, but got "' . typeOf($fhirPharmacy). '"');
        }
    }