mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-20 16:00:20 +00:00
Internet: make postURL() error reporting behaviour more predictable
err is now always set to null when doing a new operation. previously, if the same var was used multiple times and a previous one failed, code might think that a previous error belonged to the current operation.
This commit is contained in:
parent
9a130bce32
commit
97c5902ae2
@ -157,22 +157,21 @@ class Internet{
|
||||
* POSTs data to an URL
|
||||
* NOTE: This is a blocking operation and can take a significant amount of time. It is inadvisable to use this method on the main thread.
|
||||
*
|
||||
* @phpstan-template TErrorVar of mixed
|
||||
*
|
||||
* @param string[]|string $args
|
||||
* @param string[] $extraHeaders
|
||||
* @param string|null $err reference parameter, will be set to the output of curl_error(). Use this to retrieve errors that occurred during the operation.
|
||||
* @phpstan-param string|array<string, string> $args
|
||||
* @phpstan-param list<string> $extraHeaders
|
||||
* @phpstan-param TErrorVar $err
|
||||
* @phpstan-param-out TErrorVar|string $err
|
||||
* @phpstan-param-out string|null $err
|
||||
*/
|
||||
public static function postURL(string $page, array|string $args, int $timeout = 10, array $extraHeaders = [], &$err = null) : ?InternetRequestResult{
|
||||
try{
|
||||
return self::simpleCurl($page, $timeout, $extraHeaders, [
|
||||
$result = self::simpleCurl($page, $timeout, $extraHeaders, [
|
||||
CURLOPT_POST => 1,
|
||||
CURLOPT_POSTFIELDS => $args
|
||||
]);
|
||||
$err = null;
|
||||
return $result;
|
||||
}catch(InternetException $ex){
|
||||
$err = $ex->getMessage();
|
||||
return null;
|
||||
|
Loading…
x
Reference in New Issue
Block a user