-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GuzzleMiddleware issue with
Guzzle\Promise\Create::rejectionFor()
Additional file-size & complexity reduction HttpMessage/Utility/Uri::parseUrl now accepts a UriInterface (why not) Teams - can now pass a UriInterface as $url param
- Loading branch information
Showing
33 changed files
with
789 additions
and
668 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
* @package PHPDebugConsole | ||
* @author Brad Kent <[email protected]> | ||
* @license http://opensource.org/licenses/MIT MIT | ||
* @copyright 2014-2022 Brad Kent | ||
* @copyright 2014-2024 Brad Kent | ||
* @version v3.0 | ||
*/ | ||
|
||
|
@@ -96,7 +96,9 @@ public function onRejected(GuzzleException $reason, array $requestInfo) | |
} | ||
$this->logResponse($response, $requestInfo, $reason); | ||
$this->debug->groupEnd($meta); | ||
return Promise\Create::rejectionFor($reason); | ||
return \class_exists('GuzzleHttp\\Promise\\Create') | ||
? Promise\Create::rejectionFor($reason) | ||
: Promise\rejection_for($reason); | ||
} | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of PHPDebugConsole | ||
* | ||
* @package PHPDebugConsole | ||
* @author Brad Kent <[email protected]> | ||
* @license http://opensource.org/licenses/MIT MIT | ||
* @copyright 2014-2024 Brad Kent | ||
* @version v3.3 | ||
*/ | ||
|
||
namespace bdk\Debug\Route; | ||
|
||
use bdk\Debug; | ||
use bdk\ErrorHandler; | ||
use bdk\ErrorHandler\Error; | ||
|
||
/** | ||
* common "shouldSend" method | ||
*/ | ||
abstract class AbstractErrorRoute extends AbstractRoute | ||
{ | ||
protected $statsKey = ''; | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param Debug $debug debug instance | ||
*/ | ||
public function __construct(Debug $debug) | ||
{ | ||
parent::__construct($debug); | ||
$this->cfg = \array_merge($this->cfg, array( | ||
'errorMask' => E_ERROR | E_PARSE | E_COMPILE_ERROR | E_WARNING | E_USER_ERROR, | ||
)); | ||
$debug->errorHandler->setCfg('enableStats', true); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function getSubscriptions() | ||
{ | ||
return array( | ||
ErrorHandler::EVENT_ERROR => array('onError', -1), | ||
); | ||
} | ||
|
||
/** | ||
* ErrorHandler::EVENT_ERROR event subscriber | ||
* | ||
* @param Error $error error/event object | ||
* | ||
* @return void | ||
*/ | ||
public function onError(Error $error) | ||
{ | ||
if ($this->shouldSend($error, $this->statsKey) === false) { | ||
return; | ||
} | ||
$messages = $this->buildMessages($error); | ||
$this->sendMessages($messages); | ||
} | ||
|
||
/** | ||
* Build messages to send to client | ||
* | ||
* @param Error $error Error instance | ||
* | ||
* @return array | ||
*/ | ||
abstract protected function buildMessages(Error $error); | ||
|
||
/** | ||
* Send messages to client (ie Discord, Slack, or Teams) | ||
* | ||
* @param array $messages array of message(s) to send to client | ||
* | ||
* @return void | ||
*/ | ||
abstract protected function sendMessages(array $messages); | ||
|
||
/** | ||
* Should we send a notification for this error? | ||
* | ||
* @param Error $error Error instance | ||
* @param string $statsKey name under which we store stats | ||
* | ||
* @return bool | ||
*/ | ||
private function shouldSend(Error $error, $statsKey) | ||
{ | ||
if ($error['throw']) { | ||
// subscriber that set throw *should have* stopped error propagation | ||
return false; | ||
} | ||
if (($error['type'] & $this->cfg['errorMask']) !== $error['type']) { | ||
return false; | ||
} | ||
if ($error['isFirstOccur'] === false) { | ||
return false; | ||
} | ||
if ($error['inConsole']) { | ||
return false; | ||
} | ||
$error['stats'] = \array_merge(array( | ||
$statsKey => array( | ||
'countSince' => 0, | ||
'timestamp' => null, | ||
), | ||
), $error['stats'] ?: array()); | ||
$tsCutoff = \time() - $this->cfg['throttleMin'] * 60; | ||
if ($error['stats'][$statsKey]['timestamp'] > $tsCutoff) { | ||
// This error was recently sent | ||
$error['stats'][$statsKey]['countSince']++; | ||
return false; | ||
} | ||
$error['stats'][$statsKey]['timestamp'] = \time(); | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.