改进 模块异常返回
This commit is contained in:
parent
2754c37354
commit
9fa859211e
@ -14,7 +14,7 @@ public function moduleResponse($response, int $status = 200): JsonResponse
|
|||||||
201 => $this->created($response),
|
201 => $this->created($response),
|
||||||
204 => $this->noContent(),
|
204 => $this->noContent(),
|
||||||
400 => $this->badRequest($response),
|
400 => $this->badRequest($response),
|
||||||
401 => $this->serviceUnavailable(),
|
401, 502 => $this->serviceUnavailable(),
|
||||||
403 => $this->forbidden($response),
|
403 => $this->forbidden($response),
|
||||||
404 => $this->notFound($response),
|
404 => $this->notFound($response),
|
||||||
405 => $this->methodNotAllowed(),
|
405 => $this->methodNotAllowed(),
|
||||||
|
@ -4,9 +4,11 @@
|
|||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Models\Module;
|
use App\Models\Module;
|
||||||
|
use GuzzleHttp\Exception\ConnectException;
|
||||||
use Illuminate\Http\JsonResponse;
|
use Illuminate\Http\JsonResponse;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Http\Response;
|
use Illuminate\Http\Response;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
class ModuleController extends Controller
|
class ModuleController extends Controller
|
||||||
@ -24,7 +26,12 @@ public function call(Request $request, Module $module): Response|JsonResponse
|
|||||||
|
|
||||||
$method = Str::lower($request->method());
|
$method = Str::lower($request->method());
|
||||||
|
|
||||||
$response = $module->request($method, $path, $request->all());
|
try {
|
||||||
|
$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']);
|
||||||
|
Loading…
Reference in New Issue
Block a user