mirror of
https://github.com/beestat/app.git
synced 2025-07-09 03:04:07 -04:00
Made SmartyStreets failures not throw errors for #271
I still need to address the business side of things, though. For now if my subscription runs out or SmartyStreets returns garbage beestat will ignore the error and comparisons just won't work properly. Any issue caused by this will auto-resolve as soon as possible since the API call will retry automatically.
This commit is contained in:
parent
6aeceef172
commit
4d9e1e660a
@ -75,13 +75,8 @@ class external_api extends cora\api {
|
||||
curl_setopt($curl_handle, CURLINFO_HEADER_OUT, true);
|
||||
}
|
||||
|
||||
$should_cache = (
|
||||
$this::$cache === true &&
|
||||
$this::should_cache($arguments) === true
|
||||
);
|
||||
|
||||
// Check the cache
|
||||
if ($should_cache === true) {
|
||||
if ($this::$cache === true) {
|
||||
$cache_key = $this->generate_cache_key($arguments);
|
||||
$cache_entry = $this->get_cache_entry($cache_key);
|
||||
} else {
|
||||
@ -116,7 +111,10 @@ class external_api extends cora\api {
|
||||
$this->log_mysql($curl_response);
|
||||
}
|
||||
|
||||
if($should_cache === true) {
|
||||
if(
|
||||
$this::$cache === true &&
|
||||
$this::should_cache($arguments, $curl_response, $this->curl_info) === true
|
||||
) {
|
||||
$this->create_update_cache_entry($cache_key, $curl_response);
|
||||
}
|
||||
|
||||
|
@ -58,11 +58,8 @@ class smarty_streets extends external_api {
|
||||
]);
|
||||
|
||||
$response = json_decode($curl_response, true);
|
||||
if ($response === null) {
|
||||
throw new Exception('Invalid JSON');
|
||||
}
|
||||
|
||||
if (count($response) === 0) {
|
||||
if ($response === null || count($response) === 0) {
|
||||
return null;
|
||||
} else {
|
||||
// Smarty doesn't return this but I want it.
|
||||
@ -85,14 +82,19 @@ class smarty_streets extends external_api {
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether or not a request should be cached. For this, just cache
|
||||
* everything.
|
||||
* Determine whether or not a request should be cached. For this, cache
|
||||
* valid JSON responses with status code 200.
|
||||
*
|
||||
* @param array $arguments
|
||||
* @param string $curl_response
|
||||
* @param array $curl_info
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
protected function should_cache($arguments) {
|
||||
return true;
|
||||
protected function should_cache($arguments, $curl_response, $curl_info) {
|
||||
return (
|
||||
$curl_info['http_code'] === 200 &&
|
||||
json_decode($curl_response, true) !== null
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user