Spaces:
Sleeping
Sleeping
change: style on mahasiswa
Browse files
app/Http/Controllers/Controller.php
CHANGED
|
@@ -20,8 +20,8 @@ protected function ragRequest(?string $token = null): PendingRequest
|
|
| 20 |
|
| 21 |
$request = Http::baseUrl(rtrim($baseUrl, '/'))
|
| 22 |
->acceptJson()
|
| 23 |
-
->connectTimeout(
|
| 24 |
-
->timeout(
|
| 25 |
|
| 26 |
if ($token !== null && $token !== '') {
|
| 27 |
$request->withToken($token);
|
|
|
|
| 20 |
|
| 21 |
$request = Http::baseUrl(rtrim($baseUrl, '/'))
|
| 22 |
->acceptJson()
|
| 23 |
+
->connectTimeout(60)
|
| 24 |
+
->timeout(120);
|
| 25 |
|
| 26 |
if ($token !== null && $token !== '') {
|
| 27 |
$request->withToken($token);
|
app/Http/Controllers/MahasiswaController.php
CHANGED
|
@@ -3,6 +3,7 @@
|
|
| 3 |
namespace App\Http\Controllers;
|
| 4 |
|
| 5 |
use App\Exceptions\RagApiException;
|
|
|
|
| 6 |
use Illuminate\Http\JsonResponse;
|
| 7 |
use Illuminate\Http\RedirectResponse;
|
| 8 |
use Illuminate\Http\Request;
|
|
@@ -37,7 +38,7 @@ public function storeSession(Request $request): RedirectResponse
|
|
| 37 |
|
| 38 |
try {
|
| 39 |
$session = $this->createChatSession($payload, $this->authToken($request));
|
| 40 |
-
} catch (RagApiException $exception) {
|
| 41 |
return back()
|
| 42 |
->withErrors(['chat' => $exception->getMessage()])
|
| 43 |
->withInput();
|
|
@@ -62,13 +63,13 @@ public function show(Request $request, string $sessionId): Response
|
|
| 62 |
|
| 63 |
try {
|
| 64 |
$currentSession = $this->getChatSession($sessionId, $token);
|
| 65 |
-
} catch (RagApiException $exception) {
|
| 66 |
$backendMessage ??= $exception->getMessage() ?: null;
|
| 67 |
}
|
| 68 |
|
| 69 |
try {
|
| 70 |
$messages = $this->getChatHistory($sessionId, $token)['data'];
|
| 71 |
-
} catch (RagApiException $exception) {
|
| 72 |
$backendMessage ??= $exception->getMessage() ?: null;
|
| 73 |
}
|
| 74 |
|
|
@@ -114,7 +115,7 @@ public function storeMessage(Request $request, string $sessionId): JsonResponse|
|
|
| 114 |
$payload['content'],
|
| 115 |
$this->authToken($request),
|
| 116 |
);
|
| 117 |
-
} catch (RagApiException $exception) {
|
| 118 |
if ($request->expectsJson() || $request->accepts('text/event-stream')) {
|
| 119 |
return response()->json([
|
| 120 |
'errors' => [
|
|
@@ -137,7 +138,7 @@ public function storeMessage(Request $request, string $sessionId): JsonResponse|
|
|
| 137 |
$payload['content'],
|
| 138 |
$this->authToken($request),
|
| 139 |
);
|
| 140 |
-
} catch (RagApiException $exception) {
|
| 141 |
if ($request->expectsJson()) {
|
| 142 |
return response()->json([
|
| 143 |
'errors' => [
|
|
@@ -197,14 +198,14 @@ private function studentDashboardPayload(Request $request): array
|
|
| 197 |
|
| 198 |
try {
|
| 199 |
$courses = $this->listCourses(limit: 100, token: $token)['data'];
|
| 200 |
-
} catch (RagApiException $exception) {
|
| 201 |
$backendMessage = $exception->getMessage() ?: null;
|
| 202 |
}
|
| 203 |
|
| 204 |
if ($token !== null) {
|
| 205 |
try {
|
| 206 |
$chatSessions = $this->listChatSessions(limit: 20, token: $token)['data'];
|
| 207 |
-
} catch (RagApiException $exception) {
|
| 208 |
$backendMessage ??= $exception->getMessage() ?: null;
|
| 209 |
}
|
| 210 |
}
|
|
|
|
| 3 |
namespace App\Http\Controllers;
|
| 4 |
|
| 5 |
use App\Exceptions\RagApiException;
|
| 6 |
+
use Illuminate\Http\Client\ConnectionException;
|
| 7 |
use Illuminate\Http\JsonResponse;
|
| 8 |
use Illuminate\Http\RedirectResponse;
|
| 9 |
use Illuminate\Http\Request;
|
|
|
|
| 38 |
|
| 39 |
try {
|
| 40 |
$session = $this->createChatSession($payload, $this->authToken($request));
|
| 41 |
+
} catch (RagApiException|ConnectionException $exception) {
|
| 42 |
return back()
|
| 43 |
->withErrors(['chat' => $exception->getMessage()])
|
| 44 |
->withInput();
|
|
|
|
| 63 |
|
| 64 |
try {
|
| 65 |
$currentSession = $this->getChatSession($sessionId, $token);
|
| 66 |
+
} catch (RagApiException|ConnectionException $exception) {
|
| 67 |
$backendMessage ??= $exception->getMessage() ?: null;
|
| 68 |
}
|
| 69 |
|
| 70 |
try {
|
| 71 |
$messages = $this->getChatHistory($sessionId, $token)['data'];
|
| 72 |
+
} catch (RagApiException|ConnectionException $exception) {
|
| 73 |
$backendMessage ??= $exception->getMessage() ?: null;
|
| 74 |
}
|
| 75 |
|
|
|
|
| 115 |
$payload['content'],
|
| 116 |
$this->authToken($request),
|
| 117 |
);
|
| 118 |
+
} catch (RagApiException|ConnectionException $exception) {
|
| 119 |
if ($request->expectsJson() || $request->accepts('text/event-stream')) {
|
| 120 |
return response()->json([
|
| 121 |
'errors' => [
|
|
|
|
| 138 |
$payload['content'],
|
| 139 |
$this->authToken($request),
|
| 140 |
);
|
| 141 |
+
} catch (RagApiException|ConnectionException $exception) {
|
| 142 |
if ($request->expectsJson()) {
|
| 143 |
return response()->json([
|
| 144 |
'errors' => [
|
|
|
|
| 198 |
|
| 199 |
try {
|
| 200 |
$courses = $this->listCourses(limit: 100, token: $token)['data'];
|
| 201 |
+
} catch (RagApiException|ConnectionException $exception) {
|
| 202 |
$backendMessage = $exception->getMessage() ?: null;
|
| 203 |
}
|
| 204 |
|
| 205 |
if ($token !== null) {
|
| 206 |
try {
|
| 207 |
$chatSessions = $this->listChatSessions(limit: 20, token: $token)['data'];
|
| 208 |
+
} catch (RagApiException|ConnectionException $exception) {
|
| 209 |
$backendMessage ??= $exception->getMessage() ?: null;
|
| 210 |
}
|
| 211 |
}
|
resources/js/pages/mahasiswa-chat.tsx
CHANGED
|
@@ -1063,10 +1063,14 @@ export default function MahasiswaChat({
|
|
| 1063 |
}
|
| 1064 |
|
| 1065 |
setQuestion(content);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1066 |
setLocalBackendMessage(
|
| 1067 |
-
|
| 1068 |
-
? error.message
|
| 1069 |
-
: undefined,
|
| 1070 |
);
|
| 1071 |
} finally {
|
| 1072 |
const emptyStreamingMessage =
|
|
|
|
| 1063 |
}
|
| 1064 |
|
| 1065 |
setQuestion(content);
|
| 1066 |
+
const errorMessage =
|
| 1067 |
+
error instanceof Error ? error.message : '';
|
| 1068 |
+
const isGenericError =
|
| 1069 |
+
!errorMessage ||
|
| 1070 |
+
errorMessage === 'Internal Server Error' ||
|
| 1071 |
+
errorMessage === 'Server Error';
|
| 1072 |
setLocalBackendMessage(
|
| 1073 |
+
isGenericError ? undefined : errorMessage,
|
|
|
|
|
|
|
| 1074 |
);
|
| 1075 |
} finally {
|
| 1076 |
const emptyStreamingMessage =
|