Example #1
0
 /**
  * @param array $bodyDecodeResponse
  * @param Response $response
  * @return Exception\ApiProblem\DomainException|Exception\InvalidResponseException
  */
 protected function getInvalidResponseException(array $bodyDecodeResponse, Response $response)
 {
     $contentType = $response->getHeaders()->get('Content-Type');
     if ($contentType instanceof ContentType && $contentType->match('application/problem+*')) {
         $apiProblemDefaults = ['type' => $response->getReasonPhrase(), 'title' => '', 'status' => $response->getStatusCode(), 'detail' => '', 'instance' => ''];
         $bodyDecodeResponse += $apiProblemDefaults;
         //Setup remote exception
         $remoteExceptionStack = isset($bodyDecodeResponse['exception_stack']) && is_array($bodyDecodeResponse['exception_stack']) ? $bodyDecodeResponse['exception_stack'] : [];
         array_unshift($remoteExceptionStack, ['message' => $bodyDecodeResponse['detail'], 'code' => $bodyDecodeResponse['status'], 'trace' => isset($bodyDecodeResponse['trace']) ? $bodyDecodeResponse['trace'] : null]);
         //Setup exception
         $exception = new Exception\ApiProblem\DomainException($bodyDecodeResponse['detail'], $bodyDecodeResponse['status'], Exception\RemoteException::factory($remoteExceptionStack));
         $exception->setType($bodyDecodeResponse['type']);
         $exception->setTitle($bodyDecodeResponse['title']);
         foreach ($apiProblemDefaults as $key => $value) {
             unset($bodyDecodeResponse[$key]);
         }
         $exception->setAdditionalDetails($bodyDecodeResponse);
     } else {
         $exception = new Exception\InvalidResponseException($response->getReasonPhrase(), $response->getStatusCode());
         $exception->setResponse($response);
     }
     return $exception;
 }
 public function testGetAdditionalDetails()
 {
     $ex = new RemoteException();
     $this->assertSame([], $ex->getAdditionalDetails());
 }