service->isEnabled() && !$this->service->shouldExcludePath($request->path()) && $this->service->isEncryptedRequest($request)) { try { $data = $this->service->decryptRequest($request); $this->service->applyDecryptedPayload($request, $data); } catch (\Throwable $exception) { return Json::fail($exception->getMessage(), null, 400); } } $response = $handler($request); if (!$response instanceof Response) { return $response; } if (!$this->service->shouldEncrypt($request)) { return $response; } if (!$this->service->hasActiveSessionKey()) { return $response; } if (!$this->service->isJsonResponse($response)) { return $response; } try { $body = $response->rawBody(); if ($body === '') { return $response; } $encryptedBody = $this->service->encryptResponseBody($body); return $response->withBody($encryptedBody)->withHeader('Content-Type', 'application/json'); } catch (\Throwable $exception) { return Json::fail($exception->getMessage(), null, 500); } } }