log failed prefinery gets

This commit is contained in:
Alex Grintsvayg 2016-09-09 17:06:06 -04:00
parent 2bcf13b750
commit 6af882a969

View file

@ -134,9 +134,23 @@ class Prefinery
protected static function get($endpoint, array $data = []) protected static function get($endpoint, array $data = [])
{ {
$apiKey = Config::get('prefinery_key'); $apiKey = Config::get('prefinery_key');
return static::decodePrefineryResponse( $tries = 0;
Curl::get(static::DOMAIN . static::PREFIX . $endpoint . '.json?api_key=' . $apiKey, $data, array_merge(static::$curlOptions, ['retry' => 3])) $response = null;
);
while (!$response && $tries < 3)
{
$tries++;
list($status, $headers, $response) = Curl::doCurl(Curl::GET,
static::DOMAIN . static::PREFIX . $endpoint . '.json?api_key=' . $apiKey, $data, array_merge(static::$curlOptions, ['retry' => 3]));
if (!$response)
{
Controller::queueToRunAfterResponse(function() use($status, $headers, $tries) {
Slack::sendErrorIfProd('Empty prefinery get response. Try ' . $tries . '. Status: ' . $status . '. Headers: ' . var_export($headers, true));
});
}
}
return static::decodePrefineryResponse($response);
} }
protected static function post($endpoint, array $data = [], $allowEmptyResponse = true) protected static function post($endpoint, array $data = [], $allowEmptyResponse = true)