Skip to content

Commit

Permalink
Merge pull request #28 from ruuter/master
Browse files Browse the repository at this point in the history
Better error handling
  • Loading branch information
Edujugon authored Jun 11, 2020
2 parents 71963e0 + b989ddd commit 87fb3fa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 6 additions & 4 deletions src/Odoo.php
Original file line number Diff line number Diff line change
Expand Up @@ -695,19 +695,21 @@ private function buildParams($params)

/**
* Prepare the api response.
* If there is a faultCode then return its value.
* If there is a faultCode throw an exception.
* If key passed, returns the value of that key.
* Otherwise return the provided data.
*
* @param Collection $result
* @param string $key
* @param null $cast Cast returned data based on this param.
* @throws OdooException
* @return mixed
*/
private function makeResponse($result, $key = null, $cast = null)
{
if (array_key_exists('faultCode', $result->toArray()))
return $result['faultCode'];
if (array_key_exists('faultCode', $result->toArray())) {
throw new OdooException($result['faultString']);
}

if (!is_null($key) && array_key_exists($key, $result->toArray()))
$result = $result->get($key);
Expand Down Expand Up @@ -755,4 +757,4 @@ private function autoConnect()
{
if (!$this->uid) $this->connect();
}
}
}
4 changes: 3 additions & 1 deletion src/ripcord/ripcord_client.php
Original file line number Diff line number Diff line change
Expand Up @@ -482,12 +482,14 @@ public function post( $url, $request )
);
$context = stream_context_create( $options );
$result = @file_get_contents( $url, false, $context );
$this->responseHeaders = $http_response_header;

if ( !$result )
{
throw new Ripcord_TransportException( 'Could not access ' . $url,
ripcord::cannotAccessURL );
}

$this->responseHeaders = $http_response_header;
return $result;
}
}
Expand Down

0 comments on commit 87fb3fa

Please sign in to comment.