Skip to content

Commit

Permalink
Throw exception if error exists
Browse files Browse the repository at this point in the history
  • Loading branch information
Marko Dobric committed Dec 17, 2019
1 parent 9609102 commit 6e2ba1b
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/DataService/ResourceClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,17 @@ public function read(int $id): Entity
{
$entity = $this->getDataService()->FindById($this->entity, $id);

if ($error = $this->getDataService()->getLastError()) {
throw new Exception(
sprintf(
'OAuth error: %s; Response body: %s',
$error->getOAuthHelperError(),
$error->getResponseBody()
),
$error->getHttpStatusCode()
);
}

return new Entity($this->objectToArray($entity));
}

Expand All @@ -157,6 +168,17 @@ public function create(array $payload): Entity
FacadeHelper::reflectArrayToObject($this->entity, $payload)
);

if ($error = $this->getDataService()->getLastError()) {
throw new Exception(
sprintf(
'OAuth error: %s; Response body: %s',
$error->getOAuthHelperError(),
$error->getResponseBody()
),
$error->getHttpStatusCode()
);
}

return new Entity($this->objectToArray($entity));
}

Expand Down

0 comments on commit 6e2ba1b

Please sign in to comment.