mirror of https://github.com/MISP/MISP
chg: [sync] Convert connection timeout to exception
parent
c5f0aa19f1
commit
8de4a6d731
|
@ -91,6 +91,27 @@ class HttpSocketExtended extends HttpSocket
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $request
|
||||
* @return HttpSocketResponseExtended
|
||||
*/
|
||||
public function request($request = array())
|
||||
{
|
||||
// Reset last error
|
||||
$this->lastError = [];
|
||||
|
||||
/** @var HttpSocketResponseExtended $response */
|
||||
$response = parent::request($request);
|
||||
if ($response === false) {
|
||||
throw new InvalidArgumentException("Invalid argument provided.");
|
||||
}
|
||||
// Convert connection timeout to SocketException
|
||||
if (!empty($this->lastError)) {
|
||||
throw new SocketException($this->lastError['msg']);
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns accepted content encodings (compression algorithms)
|
||||
* @return string[]
|
||||
|
|
|
@ -1761,15 +1761,17 @@ class Feed extends AppModel
|
|||
|
||||
$request = $this->__createFeedRequest($feed['Feed']['headers']);
|
||||
|
||||
if ($followRedirect) {
|
||||
$response = $this->getFollowRedirect($HttpSocket, $uri, $request);
|
||||
} else {
|
||||
$response = $HttpSocket->get($uri, array(), $request);
|
||||
try {
|
||||
if ($followRedirect) {
|
||||
$response = $this->getFollowRedirect($HttpSocket, $uri, $request);
|
||||
} else {
|
||||
$response = $HttpSocket->get($uri, array(), $request);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
throw new Exception("Fetching the '$uri' failed with exception: {$e->getMessage()}", 0, $e);
|
||||
}
|
||||
|
||||
if ($response === false) {
|
||||
throw new Exception("Could not reach '$uri'.");
|
||||
} else if ($response->code != 200) { // intentionally !=
|
||||
if ($response->code != 200) { // intentionally !=
|
||||
throw new Exception("Fetching the '$uri' failed with HTTP error {$response->code}: {$response->reasonPhrase}");
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue