Skip to content

Commit

Permalink
feat: Adicionando funcao de export no BlingResponse
Browse files Browse the repository at this point in the history
  • Loading branch information
pablosanches committed Jun 18, 2024
1 parent 43e1d2a commit 2a22d96
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,13 @@ use PabloSanches\Bling\Client;
var_dump($response->getStatusCode());

// Este método indica se houve algum erro na requisição
var_dump($response->isError());
var_dump($response->hasError());

// Este método faz um unwrap do elemento error que o bling coloca por padrão em seu objeto de resposta de erros
var_dump($response->getError());

// Este método exporta o conteúdo da resposta, independente se houve erro ou sucesso
var_dump($response->export());
} catch (\Exception $e) {
// $e->getMessage();
}
Expand Down
11 changes: 10 additions & 1 deletion src/Http/BlingResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static function factory(ResponseInterface $response)
);
}

public function isError(): bool
public function hassError(): bool
{
if ($this->statusCode >= 200 && $this->statusCode < 300) {
return false;
Expand All @@ -60,4 +60,13 @@ public function getStatusCode(): int
{
return $this->statusCode;
}

public function export(): array
{
if ($this->hassError()) {
return $this->getError();
}

return $this->getData();
}
}

0 comments on commit 2a22d96

Please sign in to comment.