Skip to content
This repository has been archived by the owner on Sep 4, 2021. It is now read-only.

Do not assume http_response_header set during exception #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions lib/Consumer.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,19 @@ public static function getHTTP(string $url, string $context = ''): string
$statuscode = 'unknown';

/** @psalm-suppress UndefinedVariable */
if (preg_match('/^HTTP.*\s([0-9]{3})/', $http_response_header[0], $matches)) {
$statuscode = $matches[1];
}

$error = $context . ' [statuscode: ' . $statuscode . ']: ';
/** @psalm-suppress UndefinedVariable */
$oautherror = self::getOAuthError($http_response_header);

if (!empty($oautherror)) {
$error .= $oautherror;
if (!empty($http_response_header)) {
/** @psalm-suppress UndefinedVariable */
if (preg_match('/^HTTP.*\s([0-9]{3})/', $http_response_header[0], $matches)) {
$statuscode = $matches[1];
}

$error = $context . ' [statuscode: ' . $statuscode . ']: ';
/** @psalm-suppress UndefinedVariable */
$oautherror = self::getOAuthError($http_response_header);

if (!empty($oautherror)) {
$error .= $oautherror;
}
}

throw new \Exception($error . ':' . $url);
Expand Down