Skip to content

Commit

Permalink
[HOTFIX][FE]: Do not treat readyState 2 & 4 as an error (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicklas373 committed May 12, 2024
2 parents a67c1f8 + 86e6a4a commit 77ca96a
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 57 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ used of Flowbite library to maintain responsive and materialize interface. And p
3. Configure Server Host
````bash
- docker compose exec hana-api-services echo "TELEGRAM_BOT_ID=YOUR_TELEGRAM_BOT_ID" >> .env
- docker compose exec hana-api-services echo "TELEGRAM_TASK_ID=YOUR_TELEGRAM_CHANNEL_ID" >> .env
- docker compose exec hana-api-services echo "TELEGRAM_REPORT_ID=YOUR_TELEGRAM_CHANNEL_ID" >> .env
- docker compose exec hana-api-services echo "TELEGRAM_CHAT_ID=YOUR_TELEGRAM_CHANNEL_ID" >> .env
- docker compose exec hana-api-services echo "HANA_UNIQUE_TOKEN=YOUR_SHA512_UNIQUE_TOKEN" >> .env
- docker compose exec hana-api-services sed -i "s/ASPOSE_CLOUD_CLIENT_ID=xxxx/ASPOSE_CLOUD_CLIENT_ID=YOUR_ASPOSE_CLOUD_CLIENT_ID/" >> .env
Expand Down
58 changes: 27 additions & 31 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ public function render($request, Throwable $exception)
DB::table('appLogs')->insert([
'processId' => $uuid,
'errReason' => 'Method not allowed exception!',
'errApiReason' => $message
'errStatus' => $message
]);
DB::table('accessLogs')->insert([
'processId' => $uuid,
'routePath' => $currentRouteInfo,
'accessIpAddress' => true
'accessIpAddress' => $userIp
]);
} catch (QueryException $ex) {
Log::error('Query Exception failed with: '. $e->getMessage());
Expand All @@ -79,12 +79,12 @@ public function render($request, Throwable $exception)
DB::table('appLogs')->insert([
'processId' => $uuid,
'errReason' => 'Method not allowed exception!',
'errApiReason' => $message
'errStatus' => $message
]);
DB::table('accessLogs')->insert([
'processId' => $uuid,
'routePath' => null,
'accessIpAddress' => true
'accessIpAddress' => $userIp
]);
} catch (QueryException $ex) {
Log::error('Query Exception failed with: '. $e->getMessage());
Expand All @@ -98,12 +98,12 @@ public function render($request, Throwable $exception)
DB::table('appLogs')->insert([
'processId' => $uuid,
'errReason' => 'Token Mismatch exception!',
'errApiReason' => $message
'errStatus' => $message
]);
DB::table('accessLogs')->insert([
'processId' => $uuid,
'routePath' => $currentRouteInfo,
'accessIpAddress' => true
'accessIpAddress' => $userIp
]);
} catch (QueryException $ex) {
Log::error('Query Exception failed with: '. $e->getMessage());
Expand All @@ -116,7 +116,7 @@ public function render($request, Throwable $exception)
DB::table('appLogs')->insert([
'processId' => $uuid,
'errReason' => 'Route not found exception!',
'errApiReason' => $message
'errStatus' => $message
]);
DB::table('accessLogs')->insert([
'processId' => $uuid,
Expand All @@ -139,12 +139,12 @@ public function render($request, Throwable $exception)
DB::table('appLogs')->insert([
'processId' => $uuid,
'errReason' => '404 - Page not found',
'errApiReason' => $message
'errStatus' => $message
]);
DB::table('accessLogs')->insert([
'processId' => $uuid,
'routePath' => $currentRouteInfo,
'accessIpAddress' => true
'accessIpAddress' => $userIp
]);
} catch (QueryException $ex) {
Log::error('Query Exception failed with: '. $e->getMessage());
Expand All @@ -156,13 +156,13 @@ public function render($request, Throwable $exception)
DB::table('appLogs')->insert([
'processId' => $uuid,
'errReason' => '403 - Forbidden',
'errApiReason' => $message
]);
DB::table('accessLogs')->insert([
'processId' => $uuid,
'routePath' => $currentRouteInfo,
'accessIpAddress' => true
'errStatus' => $message
]);
DB::table('accessLogs')->insert([
'processId' => $uuid,
'routePath' => $currentRouteInfo,
'accessIpAddress' => $userIp
]);
} catch (QueryException $ex) {
Log::error('Query Exception failed with: '. $e->getMessage());
}
Expand All @@ -173,12 +173,12 @@ public function render($request, Throwable $exception)
DB::table('appLogs')->insert([
'processId' => $uuid,
'errReason' => '419 - Page Expired',
'errApiReason' => $message
'errStatus' => $message
]);
DB::table('accessLogs')->insert([
'processId' => $uuid,
'routePath' => $currentRouteInfo,
'accessIpAddress' => true
'accessIpAddress' => $userIp
]);
} catch (QueryException $ex) {
Log::error('Query Exception failed with: '. $e->getMessage());
Expand All @@ -190,13 +190,13 @@ public function render($request, Throwable $exception)
DB::table('appLogs')->insert([
'processId' => $uuid,
'errReason' => '429 - Too Many Requests',
'errApiReason' => $message
]);
DB::table('accessLogs')->insert([
'processId' => $uuid,
'routePath' => $currentRouteInfo,
'accessIpAddress' => true
'errStatus' => $message
]);
DB::table('accessLogs')->insert([
'processId' => $uuid,
'routePath' => $currentRouteInfo,
'accessIpAddress' => $userIp
]);
} catch (QueryException $ex) {
Log::error('Query Exception failed with: '. $e->getMessage());
}
Expand All @@ -207,14 +207,12 @@ public function render($request, Throwable $exception)
DB::table('appLogs')->insert([
'processId' => $uuid,
'errReason' => '500 - Internal Server Error',
'errApiReason' => $message
'errStatus' => $message
]);
DB::table('accessLogs')->insert([
'processId' => $uuid,
'routePath' => $currentRouteInfo,
'accessIpAddress' => true,
'routeExceptionMessage' => '500 - Internal Server Error',
'routeExceptionLog' => $message
'accessIpAddress' => $userIp
]);
} catch (QueryException $ex) {
Log::error('Query Exception failed with: '. $e->getMessage());
Expand All @@ -226,14 +224,12 @@ public function render($request, Throwable $exception)
DB::table('appLogs')->insert([
'processId' => $uuid,
'errReason' => '503 - Service Temporary Unavailable',
'errApiReason' => $message
'errStatus' => $message
]);
DB::table('accessLogs')->insert([
'processId' => $uuid,
'routePath' => $currentRouteInfo,
'accessIpAddress' => true,
'routeExceptionMessage' => '503 - Service Temporary Unavailable',
'routeExceptionLog' => $message
'accessIpAddress' => $userIp
]);
} catch (QueryException $ex) {
Log::error('Query Exception failed with: '. $e->getMessage());
Expand Down
29 changes: 19 additions & 10 deletions app/Helpers/NotificationHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,17 @@ function sendRouteErrNotify($processId, $status, $errReason, $errRoute, $errCode
$messageId = $response->getMessageId();

try {
DB::table('appLogs')->insert([
'processId' => $processId,
'errReason' => null,
'errApiReason' => null,
]);
DB::table('notifyLogs')->insert([
'processId' => $processId,
'notifyName' => 'Telegram SDK',
'notifyResult' => true,
'notifyMessage' => 'Message has been sent !',
'notifyResponse' => $response,
'notifyErrStatus' => $errReason,
'notifyErrMessage' => $errCode
'notifyResponse' => $response
]);
} catch (QueryException $ex) {
Log::error('Query Exception failed with: '. $ex->getMessage());
Expand All @@ -55,28 +58,34 @@ function sendRouteErrNotify($processId, $status, $errReason, $errRoute, $errCode
} else {
$httpStatus = $e->getHttpStatusCode();
}
DB::table('appLogs')->insert([
'processId' => $processId,
'errReason' => 'TelegramResponseException',
'errApiReason' => $e->getMessage(),
]);
DB::table('notifyLogs')->insert([
'processId' => $processId,
'notifyName' => 'Telegram SDK',
'notifyResult' => false,
'notifyMessage' => $e->getMessage(),
'notifyResponse' => null,
'notifyErrStatus' => $httpStatus,
'notifyErrMessage' => $e->getErrorType()
'notifyMessage' => 'TelegramResponseException',
'notifyResponse' => $e->getMessage()+' | '+$httpStatus+' | '+$e->getErrorType()
]);
} catch (QueryException $ex) {
Log::error('Query Exception failed with: '. $ex->getMessage());
}
} catch (\Exception $e) {
try {
DB::table('appLogs')->insert([
'processId' => $processId,
'errReason' => 'Unexpected handling exception !',
'errApiReason' => $e->getMessage(),
]);
DB::table('notifyLogs')->insert([
'processId' => $processId,
'notifyName' => 'Telegram SDK',
'notifyResult' => false,
'notifyMessage' => 'Unexpected handling exception !',
'notifyResponse' => null,
'notifyErrStatus' => null,
'notifyErrMessage' => $e->getMessage()
'notifyResponse' => $e->getMessage()
]);
} catch (QueryException $ex) {
Log::error('Query Exception failed with: '. $ex->getMessage());
Expand Down

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/build/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
]
},
"resources/js/kao-logic.js": {
"file": "assets/kao-logic-DB00_MMO.js",
"file": "assets/kao-logic-iKWRdJWb.js",
"name": "kao-logic",
"src": "resources/js/kao-logic.js",
"isEntry": true,
Expand Down
25 changes: 15 additions & 10 deletions resources/js/kao-logic.js
Original file line number Diff line number Diff line change
Expand Up @@ -848,15 +848,20 @@ function apiGateway(proc, action) {
sendToAPI(files,proc,action).then(function () {
loadingModal.hide()
}).catch(function (error) {
errModal.hide()
errMessage.innerText = "There was unexpected error !"
errSubMessage.innerText = ""
errListTitleMessage.innerText = "Error message"
resetErrListMessage()
generateMesssage(error.xhrRequestStatus+" - "+error.xhrRequestMessage)
errAltSubMessageModal.style = null
loadingModal.hide()
errModal.show()
if (error.xhrRequestStatus == 2 || error.xhrRequestStatus == 4) {
// Do not treat this status as error
loadingModal.hide()
} else {
errModal.hide()
errMessage.innerText = "There was unexpected error !"
errSubMessage.innerText = ""
errListTitleMessage.innerText = "Error message"
resetErrListMessage()
generateMesssage(error.xhrRequestStatus+" - "+error.xhrRequestMessage)
errAltSubMessageModal.style = null
loadingModal.hide()
errModal.show()
}
})
}

Expand Down Expand Up @@ -1169,7 +1174,7 @@ function sendToAPI(files, proc, action) {
xhrRequestCondition: 'ERROR',
xhrRequestMessage: 'Server are not in readyState ! ('+xhr.readyState+')',
xhrRequestServerMessage: '',
xhrRequestStatus: 0
xhrRequestStatus: xhr.readyState
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion resources/views/layouts/alternate-layout.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<div id="content" class="flex flex-col min-h-screen justify-between">
@yield('content')
</div>
<script async type="module" src="{{asset('build/assets/kao-logic-DB00_MMO.js')}}"></script>
<script async type="module" src="{{asset('build/assets/kao-logic-iKWRdJWb.js')}}"></script>
<script async type="module" src="https://unpkg.com/pdfjs-dist@4.0.379/build/pdf.mjs"></script>
<script async type="module" src="https://unpkg.com/pdfjs-dist@4.0.379/build/pdf.worker.mjs"></script>
<script async type="text/javascript" src="{{asset('ext-js/kao-controller.js')}}"></script>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/layouts/main-layout.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<div id="content" class="flex flex-col min-h-screen justify-between">
@yield('content')
</div>
<script async type="module" src="{{asset('build/assets/kao-logic-DB00_MMO.js')}}"></script>
<script async type="module" src="{{asset('build/assets/kao-logic-iKWRdJWb.js')}}"></script>
<script async type="text/javascript" src="{{asset('ext-js/kao-controller.js')}}"></script>
<script async type="text/javascript" src="{{asset('ext-js/kao-main.js')}}"></script>
<script async type="text/javascript" src="https://unpkg.com/@material-tailwind/html@latest/scripts/ripple.js"></script>
Expand Down

0 comments on commit 77ca96a

Please sign in to comment.