mirror of
https://github.com/jikan-me/jikan-rest.git
synced 2025-02-20 11:23:35 +08:00
add connect/request timeout + options
This commit is contained in:
parent
f6de29826d
commit
bf789210fb
@ -37,6 +37,12 @@ SOURCE_BAD_HEALTH_RECHECK=10
|
||||
SOURCE_BAD_HEALTH_RANGE=30
|
||||
# Max Fail stores
|
||||
SOURCE_BAD_HEALTH_MAX_STORE=50
|
||||
# Max time request is allowed to take
|
||||
# https://curl.haxx.se/libcurl/c/CURLOPT_TIMEOUT.html
|
||||
SOURCE_TIMEOUT=5
|
||||
# Timeout for connect phase
|
||||
# https://curl.haxx.se/libcurl/c/CURLOPT_CONNECTTIMEOUT.html
|
||||
SOURCE_CONNECT_TIMEOUT=5
|
||||
|
||||
###
|
||||
# Caching (File, Redis, etc)
|
||||
|
@ -6,6 +6,7 @@ use App\Events\SourceHealthEvent;
|
||||
use App\Http\HttpHelper;
|
||||
use Exception;
|
||||
use GuzzleHttp\Exception\ClientException;
|
||||
use GuzzleHttp\Exception\ConnectException;
|
||||
use Illuminate\Auth\Access\AuthorizationException;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Illuminate\Http\Request;
|
||||
@ -75,6 +76,16 @@ class Handler extends ExceptionHandler
|
||||
], 500);
|
||||
}
|
||||
|
||||
if ($e instanceof ConnectException) {
|
||||
return response()
|
||||
->json([
|
||||
'status' => $e->getCode(),
|
||||
'type' => 'BadResponseException',
|
||||
'message' => 'Jikan failed to connect to MyAnimeList. MyAnimeList may be down/unavailable or refuses to connect',
|
||||
'error' => $e->getMessage()
|
||||
], 503);
|
||||
}
|
||||
|
||||
// ParserException from Jikan PHP API
|
||||
if ($e instanceof ParserException) {
|
||||
$githubReport->setRepo(env('GITHUB_API', 'jikan-me/jikan'));
|
||||
@ -88,6 +99,8 @@ class Handler extends ExceptionHandler
|
||||
], 500);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// BadResponseException from Guzzle dep via Jikan PHP API
|
||||
// This is basically the response MyAnimeList returns to Jikan
|
||||
if ($e instanceof BadResponseException || $e instanceof ClientException) {
|
||||
|
@ -106,7 +106,10 @@ if (env('CACHING')) {
|
||||
|
||||
$app->register(Flipbox\LumenGenerator\LumenGeneratorServiceProvider::class);
|
||||
|
||||
$guzzleClient = new \GuzzleHttp\Client();
|
||||
$guzzleClient = new \GuzzleHttp\Client([
|
||||
'timeout' => env('SOURCE_TIMEOUT', 5),
|
||||
'connect_timeout' => env('SOURCE_CONNECT_TIMEOUT', 5)
|
||||
]);
|
||||
$app->instance('GuzzleClient', $guzzleClient);
|
||||
|
||||
$jikan = new \Jikan\MyAnimeList\MalClient(app('GuzzleClient'));
|
||||
|
Loading…
x
Reference in New Issue
Block a user