Skip to content

Commit

Permalink
Merge pull request #16 from telebugs/guzzlify-promises
Browse files Browse the repository at this point in the history
Don't wrap Guzzle promises with our Promise wrapper
  • Loading branch information
kyrylo authored Jul 26, 2024
2 parents 789c891 + 4362b65 commit 4345383
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 102 deletions.
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,13 @@ Telebugs\configure(function ($config) {
$config->setApiKey("YOUR_API_KEY");
});


try {
1 / 0;
} catch (DivisionByZeroError $e) {
Telebugs\report($e);
Telebugs\report($e)->wait();
}

sleep(2);

echo "An error was sent to Telebugs asynchronously." .
echo "An error was sent to Telebugs." .
"It will appear in your dashboard shortly." .
"A notification was also sent to your Telegram chat."
?>
Expand Down
38 changes: 0 additions & 38 deletions src/Promise.php

This file was deleted.

8 changes: 4 additions & 4 deletions src/Reporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
namespace Telebugs;

use GuzzleHttp\Promise\FulfilledPromise;
use GuzzleHttp\Promise\PromiseInterface;

use Telebugs\Promise;
use Telebugs\Sender;
use Telebugs\Config;

class Reporter
{
public const VERSION = '0.1.0';
public const VERSION = '0.2.0';

private static ?Reporter $instance = null;

Expand All @@ -31,13 +31,13 @@ public function __construct()
$this->config = Config::getInstance();
}

public function report(\Throwable $e): Promise
public function report(\Throwable $e): PromiseInterface
{
$report = new Report($e);

$this->config->middleware()($report);
if ($report->ignored) {
return new Promise(new FulfilledPromise("Report ignored"));
return new FulfilledPromise("Report ignored");
}

return $this->sender->send($report);
Expand Down
7 changes: 3 additions & 4 deletions src/Sender.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace Telebugs;

use Telebugs\Promise;
use Telebugs\Config;
use Telebugs\Report;

use GuzzleHttp\Promise\PromiseInterface;
use Psr\Http\Message\ResponseInterface;

class Sender
Expand All @@ -21,9 +21,9 @@ public function __construct()
$this->config = Config::getInstance();
}

public function send(Report $report): Promise
public function send(Report $report): PromiseInterface
{
$guzzlePromise = $this->config->getHttpClient()->postAsync($this->config->getApiURL(), [
$promise = $this->config->getHttpClient()->postAsync($this->config->getApiURL(), [
'body' => json_encode($report),
'headers' => [
'Content-Type' => self::CONTENT_TYPE,
Expand All @@ -32,7 +32,6 @@ public function send(Report $report): Promise
]
]);

$promise = new Promise($guzzlePromise);
return $promise->then(function (ResponseInterface $res) {
return json_decode($res->getBody()->getContents(), true);
});
Expand Down
5 changes: 3 additions & 2 deletions src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@

use Telebugs\Config;
use Telebugs\Reporter;
use Telebugs\Promise;

use GuzzleHttp\Promise\PromiseInterface;

function configure(\Closure $callback): void
{
$callback(Config::getInstance());
}

function report(\Throwable $e): Promise
function report(\Throwable $e): PromiseInterface
{
return Reporter::getInstance()->report($e);
}
49 changes: 0 additions & 49 deletions tests/PromiseTest.php

This file was deleted.

0 comments on commit 4345383

Please sign in to comment.