original_string: public function convertErrorToModel(array $response, $resourceName = null)
      {
          $errorModel = new Error();
  
          $httpStatusCode = isset($response['header']['status']) ? $response['header']['status'] : null;
          $errorModel->setHttpStatusCode($httpStatusCode);
  
          $responseCode = isset($response['body']['data']['response_code']) ? $response['body']['data']['response_code'] : null;
          $errorModel->setResponseCode($responseCode);
  
          $errorCode = 'Undefined Error. This should not happen!';
          $rawError = array();
  
          if (isset($this->_errorCodes[$responseCode])) {
              $errorCode = $this->_errorCodes[$responseCode];
          }
  
          if (isset($resourceName) && isset($response['body']['data'])) {
              try {
                  $errorModel->setRawObject($this->convertResponse($response['body']['data'], $resourceName));
              } catch (\Exception $e) { }
          }
  
          if (isset($response['body'])) {
              if (is_array($response['body'])) {
                  if (isset($response['body']['error'])) {
                      $rawError = $response['body']['error'];
                      if (is_array($response['body']['error'])) {
                          $errorCode = $this->getErrorMessageFromArray($response['body']['error']);
                      } elseif (is_string($response['body']['error'])) {
                          $errorCode = $response['body']['error'];
                      }
                  }
              } elseif (is_string($response['body'])) {
                  $json = json_decode($response['body'], true);
                  if (isset($json['error'])) {
                      $errorCode = $json['error'];
                      $rawError = $json['error'];
                  }
              }
          }
  
          $errorModel->setErrorMessage($errorCode);
          $errorModel->setErrorResponseArray(array('error' => $rawError));
  
          return $errorModel;
      }
code: public function convertErrorToModel(array $response, $resourceName = null)
      {
          $errorModel = new Error();
  
          $httpStatusCode = isset($response['header']['status']) ? $response['header']['status'] : null;
          $errorModel->setHttpStatusCode($httpStatusCode);
  
          $responseCode = isset($response['body']['data']['response_code']) ? $response['body']['data']['response_code'] : null;
          $errorModel->setResponseCode($responseCode);
  
          $errorCode = 'Undefined Error. This should not happen!';
          $rawError = array();
  
          if (isset($this->_errorCodes[$responseCode])) {
              $errorCode = $this->_errorCodes[$responseCode];
          }
  
          if (isset($resourceName) && isset($response['body']['data'])) {
              try {
                  $errorModel->setRawObject($this->convertResponse($response['body']['data'], $resourceName));
              } catch (\Exception $e) { }
          }
  
          if (isset($response['body'])) {
              if (is_array($response['body'])) {
                  if (isset($response['body']['error'])) {
                      $rawError = $response['body']['error'];
                      if (is_array($response['body']['error'])) {
                          $errorCode = $this->getErrorMessageFromArray($response['body']['error']);
                      } elseif (is_string($response['body']['error'])) {
                          $errorCode = $response['body']['error'];
                      }
                  }
              } elseif (is_string($response['body'])) {
                  $json = json_decode($response['body'], true);
                  if (isset($json['error'])) {
                      $errorCode = $json['error'];
                      $rawError = $json['error'];
                  }
              }
          }
  
          $errorModel->setErrorMessage($errorCode);
          $errorModel->setErrorResponseArray(array('error' => $rawError));
  
          return $errorModel;
      }
code_tokens: public function convertErrorToModel ( array $ response , $ resourceName = null ) { $ errorModel = new Error ( ) ; $ httpStatusCode = isset ( $ response [ 'header' ] [ 'status' ] ) ? $ response [ 'header' ] [ 'status' ] : null ; $ errorModel -> setHttpStatusCode ( $ httpStatusCode ) ; $ responseCode = isset ( $ response [ 'body' ] [ 'data' ] [ 'response_code' ] ) ? $ response [ 'body' ] [ 'data' ] [ 'response_code' ] : null ; $ errorModel -> setResponseCode ( $ responseCode ) ; $ errorCode = 'Undefined Error. This should not happen!' ; $ rawError = array ( ) ; if ( isset ( $ this -> _errorCodes [ $ responseCode ] ) ) { $ errorCode = $ this -> _errorCodes [ $ responseCode ] ; } if ( isset ( $ resourceName ) && isset ( $ response [ 'body' ] [ 'data' ] ) ) { try { $ errorModel -> setRawObject ( $ this -> convertResponse ( $ response [ 'body' ] [ 'data' ] , $ resourceName ) ) ; } catch ( \ Exception $ e ) { } } if ( isset ( $ response [ 'body' ] ) ) { if ( is_array ( $ response [ 'body' ] ) ) { if ( isset ( $ response [ 'body' ] [ 'error' ] ) ) { $ rawError = $ response [ 'body' ] [ 'error' ] ; if ( is_array ( $ response [ 'body' ] [ 'error' ] ) ) { $ errorCode = $ this -> getErrorMessageFromArray ( $ response [ 'body' ] [ 'error' ] ) ; } elseif ( is_string ( $ response [ 'body' ] [ 'error' ] ) ) { $ errorCode = $ response [ 'body' ] [ 'error' ] ; } } } elseif ( is_string ( $ response [ 'body' ] ) ) { $ json = json_decode ( $ response [ 'body' ] , true ) ; if ( isset ( $ json [ 'error' ] ) ) { $ errorCode = $ json [ 'error' ] ; $ rawError = $ json [ 'error' ] ; } } } $ errorModel -> setErrorMessage ( $ errorCode ) ; $ errorModel -> setErrorResponseArray ( array ( 'error' => $ rawError ) ) ; return $ errorModel ; }
docstring: Generates an error model based on the provided response array
  @param array $response
  @param string $resourceName
  @return Error
docstring_tokens: Generates an error model based on the provided response array