改进 异常抛出
This commit is contained in:
parent
9fa859211e
commit
94d7e13c6a
@ -26,12 +26,7 @@ public function call(Request $request, Module $module): Response|JsonResponse
|
|||||||
|
|
||||||
$method = Str::lower($request->method());
|
$method = Str::lower($request->method());
|
||||||
|
|
||||||
try {
|
$response = $module->request($method, $path, $request->all());
|
||||||
$response = $module->request($method, $path, $request->all());
|
|
||||||
} catch (ConnectException $e) {
|
|
||||||
Log::error('在执行 call ' . $method . ' ' . $path . ' 时发生错误: ' . $e->getMessage());
|
|
||||||
return $this->serviceUnavailable();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($response['json'] === null && $response['body'] !== null) {
|
if ($response['json'] === null && $response['body'] !== null) {
|
||||||
return response($response['body'], $response['status']);
|
return response($response['body'], $response['status']);
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
use GuzzleHttp\Exception\ConnectException;
|
use GuzzleHttp\Exception\ConnectException;
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||||
|
use Illuminate\Http\Client\ConnectionException;
|
||||||
use Illuminate\Http\Client\PendingRequest;
|
use Illuminate\Http\Client\PendingRequest;
|
||||||
use Illuminate\Http\Client\Response;
|
use Illuminate\Http\Client\Response;
|
||||||
use Illuminate\Support\Facades\Cache;
|
use Illuminate\Support\Facades\Cache;
|
||||||
@ -113,9 +114,26 @@ private function getResponse(Response $response): array
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $method
|
||||||
|
* @param $path
|
||||||
|
* @param $requests
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
public function request($method, $path, $requests): array
|
public function request($method, $path, $requests): array
|
||||||
{
|
{
|
||||||
return $this->baseRequest($method, "functions/$path", $requests);
|
try {
|
||||||
|
return $this->baseRequest($method, "functions/$path", $requests);
|
||||||
|
} catch (ConnectException|ConnectionException $e) {
|
||||||
|
Log::error('在执行 call ' . $method . ' ' . $path . ' 时发生错误: ' . $e->getMessage());
|
||||||
|
return [
|
||||||
|
'body' => null,
|
||||||
|
'json' => null,
|
||||||
|
'status' => 502,
|
||||||
|
'success' => false,
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function baseRequest($method, $path, $requests = []): array
|
public function baseRequest($method, $path, $requests = []): array
|
||||||
|
Loading…
Reference in New Issue
Block a user