Skip to content

Commit

Permalink
[HOTFIX][FE]: Try properly render exceptions page (#296)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicklas373 authored Dec 2, 2024
2 parents 8520d6d + 151ca70 commit f29c30c
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 61 deletions.
154 changes: 102 additions & 52 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ used of Flowbite library to maintain responsive and materialize interface. And p
- On Linux use docker-compose and docker.io
- [Node JS 20.11](https://nodejs.org/en)
- [PHP 8.2.12](https://www.php.net/downloads.php)
- [PostgreSQL 16.2](https://www.postgresql.org/)
- [PostgreSQL 17.0](https://www.postgresql.org/)
- [Postman](https://www.postman.com/)

---
Expand Down Expand Up @@ -80,7 +80,6 @@ used of Flowbite library to maintain responsive and materialize interface. And p
```
4. Configure Client Host
```bash
- docker compose exec hana-app-pdf sed -i "s/VITE_ADOBE_CLIENT_ID=xxxx/VITE_ADOBE_CLIENT_ID=YOUR_ADOBE_CLIENT_ID/" >> .env
- docker compose exec hana-app-pdf echo "TELEGRAM_BOT_ID=YOUR_TELEGRAM_BOT_ID" >> .env
- docker compose exec hana-app-pdf echo "TELEGRAM_CHAT_ID=YOUR_TELEGRAM_CHANNEL_ID" >> .env
- docker compose exec hana-app-pdf chmod o+w /var/www/html/hanaci-pdf/storage/ -R
Expand All @@ -99,7 +98,31 @@ used of Flowbite library to maintain responsive and materialize interface. And p
- docker compose exec hana-app-pdf sed -i 's|http://192.168.0.2|YOUR_BACKEND_URL:PORT|' public/build/assets/kao-logic-CHECK_LATEST_REVISION.js
- docker compose exec hana-app-pdf sed -i 's|STATIC_CLIENT_ID|YOUR_ADOBE_CLIENT_ID|' public/build/assets/kao-logic-CHECK_LATEST_REVISION.js
```
6. Refresh page and done.
6. Configure Min.io
- Open minio console page, URL: http://YOUR_LOCAL_IP:9001
- Go to administrator -> bucket
- Create new bucket with name "hana-pdf"
- Go to user -> access key
- Create new access key
- Check "Restrict beyond user policy"
- Fill custom policy
```bash
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": ["s3:GetObject", "s3:ListBucket", "s3:PutObject"],
"Resource": ["arn:aws:s3:::hana-pdf", "arn:aws:s3:::hana-pdf/*"]
}
]
}
```
- Copy Access key into backend module environment "MINIO_ACCESS_KEY"
- Copy Secret key into backend module environment "MINIO_SECRET_KEY"
- Set name access key into "hana-pdf"
- Create access key
7. Refresh page and done.

---

Expand All @@ -112,7 +135,6 @@ used of Flowbite library to maintain responsive and materialize interface. And p
A. Copy **.env.example** file to **.env** and modify database credentials

```bash
- VITE_ADOBE_CLIENT_ID="ADOBE_CLIENT_ID" [https://developer.adobe.com/document-services/docs/overview/pdf-embed-api/]
- VITE_JWT_TOKEN="YOUR_CURRENT_BEARER_TOKEN" [Get it from Backend with route api/v1/auth/getToken]
- TELEGRAM_BOT_ID="YOUR_TELEGRAM_BOT_ID" [https://telegram-bot-sdk.com/docs/getting-started/installation]
- TELEGRAM_CHAT_ID="YOUR_TELEGRAM_CHANNEL_ID" [https://telegram-bot-sdk.com/docs/getting-started/installation]
Expand All @@ -135,52 +157,80 @@ used of Flowbite library to maintain responsive and materialize interface. And p

2. Clone the repository with branch \_\_dev/be/master [Backend Services]

A. Copy **.env.example** file to **.env** and modify database credentials

```bash
- ASPOSE_CLOUD_CLIENT_ID="ASPOSE_CLOUD_CLIENT_ID" [https://dashboard.aspose.cloud/]
- ASPOSE_CLOUD_TOKEN="ASPOSE_CLOUD_TOKEN" [https://dashboard.aspose.cloud/]
- FTP_USERNAME="FTP_USERNAME" [https://dashboard.aspose.cloud/]
- FTP_USERPASS="FTP_USERPASS" [https://dashboard.aspose.cloud/]
- FTP_SERVER="FTP_SERVER" [https://dashboard.aspose.cloud/]
- ILOVEPDF_ENC_KEY="ILOVEPDF_ENC_KEY" [Generate your hash key (Max. 25 digits)]
- ILOVEPDF_PUBLIC_KEY="ILOVEPDF_PUBLIC_KEY" [https://developer.ilovepdf.com/]
- ILOVEPDF_SECRET_KEY="ILOVEPDF_SECRET_KEY" [https://developer.ilovepdf.com/]
- PDF_IMG_POOL="image"
- PDF_BATCH="batch"
- PDF_UPLOAD="upload"
- PDF_DOWNLOAD="download"
- PDF_POOL="pool"
- TELEGRAM_BOT_ID="YOUR_TELEGRAM_BOT_ID" [https://telegram-bot-sdk.com/docs/getting-started/installation]
- TELEGRAM_CHAT_ID="YOUR_TELEGRAM_CHANNEL_ID" [https://telegram-bot-sdk.com/docs/getting-started/installation]
- HANA_UNIQUE_TOKEN="YOUR_SHA512_UNIQUE_TOKEN"
```

B. Run the following command [Make sure to configure database connectivity before use migrate function]

```bash
- composer install
- php artisan key:generate
- php artisan jwt:secret
- php artisan storage:link
```

C. Create new directory inside storage/app/public

- image
- batch
- upload
- download
- pool

D. Start to deploy

```bash
- npm run dev -- --host
- php artisan serve --host=localhost --port=80
```

E. Configure apiUrl variable on resources/js/kao-logic.js to your considered BE address and port !
- Copy **.env.example** file to **.env** and modify database credentials
```bash
- ASPOSE_CLOUD_CLIENT_ID="ASPOSE_CLOUD_CLIENT_ID" [https://dashboard.aspose.cloud/]
- ASPOSE_CLOUD_TOKEN="ASPOSE_CLOUD_TOKEN" [https://dashboard.aspose.cloud/]
- FTP_USERNAME="FTP_USERNAME" [https://dashboard.aspose.cloud/]
- FTP_USERPASS="FTP_USERPASS" [https://dashboard.aspose.cloud/]
- FTP_SERVER="FTP_SERVER" [https://dashboard.aspose.cloud/]
- ILOVEPDF_ENC_KEY="ILOVEPDF_ENC_KEY" [Generate your hash key (Max. 25 digits)]
- ILOVEPDF_PUBLIC_KEY="ILOVEPDF_PUBLIC_KEY" [https://developer.ilovepdf.com/]
- ILOVEPDF_SECRET_KEY="ILOVEPDF_SECRET_KEY" [https://developer.ilovepdf.com/]
- PDF_IMG_POOL="image"
- PDF_BATCH="batch"
- PDF_UPLOAD="upload"
- PDF_DOWNLOAD="download"
- PDF_POOL="pool"
- TELEGRAM_BOT_ID="YOUR_TELEGRAM_BOT_ID" [https://telegram-bot-sdk.com/docs/getting-started/installation]
- TELEGRAM_CHAT_ID="YOUR_TELEGRAM_CHANNEL_ID" [https://telegram-bot-sdk.com/docs/getting-started/installation]
- HANA_UNIQUE_TOKEN="YOUR_SHA512_UNIQUE_TOKEN"
- MINIO_ACCESS_KEY="YOUR_MINIO_ACCESS_KEY"
- MINIO_SECRET_KEY="YOUR_MINIO_SECRET_KEY"
- MINIO_ENDPOINT="YOUR_MINIO_ENDPOINT_URL"
```
- Run the following command [Make sure to configure database connectivity before use migrate function]
```bash
- composer install
- php artisan key:generate
- php artisan jwt:secret
- php artisan storage:link
```
- Create new directory inside storage/app/public
- image
- batch
- upload
- download
- pool
- Configure REST API
- Install Postman
- Create a new HTTP request with POST format
- URL: http://YOUR_LOCAL_IP:YOUR_LOCAL_PORT/api/v1/auth/getToken
- Body: form-data
- email: eureka@hana-ci.com
- password: YOUR_SHA512_UNIQUE_TOKEN
- Send a POST request to get access token
- Configure frontend credentials
- Set adobeClientID -> YOUR_ADOBE_CLIENT_ID
- Set apiUrl -> YOUR_BACKEND_URL
- Set bearerToken -> response token
- Configure Min.io
- Open minio console page, URL: http://YOUR_LOCAL_IP:9001
- Go to administrator -> bucket - Create new bucket with name "hana-pdf"
- Go to user -> access key - Create new access key
- Check "Restrict beyond user policy"
- Fill custom policy
```bash
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": ["s3:GetObject", "s3:ListBucket", "s3:PutObject"],
"Resource": ["arn:aws:s3:::hana-pdf", "arn:aws:s3:::hana-pdf/*"]
}
]
}
```
- Copy Access key into backend module environment "MINIO_ACCESS_KEY"
- Copy Secret key into backend module environment "MINIO_SECRET_KEY"
- Set name access key into "hana-pdf"
- Create access key
- Start to deploy
```bash
- npm run dev -- --host
- php artisan serve --host=localhost --port=80
```

---

Expand All @@ -190,9 +240,9 @@ used of Flowbite library to maintain responsive and materialize interface. And p
- [DropzoneJS](https://www.dropzone.dev/)
- [Flowbite](https://flowbite.com/)
- [Laravel](https://laravel.com/)
- [Minio](https://min.io/)
- [Min.io](https://min.io/)
- [Node JS](https://nodejs.org/en)
- [Mozilla PDFJS](https://mozilla.github.io/pdf.js/)
- [Mozilla PDF.JS](https://mozilla.github.io/pdf.js/)
- [Tailwind CSS](https://tailwindcss.com/)
- [Vite JS](https://vitejs.dev/)

Expand Down
18 changes: 9 additions & 9 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function render($request, Throwable $exception)
]);
Log::error($message);
}
abort(403);
return response()->view('errors.403', [], 403);
} else if ($exception instanceof TokenMismatchException || ($exception instanceof HttpException && $exception->getStatusCode() == 419)) {
$message = 'TokenMismatchException: ' . $exception->getMessage();
Log::error($message);
Expand All @@ -89,15 +89,15 @@ public function render($request, Throwable $exception)
'errReason' => $message,
'errStatus' => 'TokenMismatchException'
]);
abort(401);
return response()->view('errors.401', [], 401);
} else if ($exception instanceof RouteNotFoundException) {
$message = 'RouteNotFoundException: ' . $exception->getMessage();
appLogModel::where('groupId', '=', $Muuid)
->update([
'errReason' => $message,
'errStatus' => 'Route not found exception!'
]);
abort(404);
return response()->view('errors.404', [], 404);
} else if ($exception instanceof NotFoundHttpException || ($exception instanceof HttpException && $exception->getStatusCode() == 404)) {
$message = 'NotFoundHttpException: ' . $exception->getMessage();
Log::error($message);
Expand All @@ -106,7 +106,7 @@ public function render($request, Throwable $exception)
'errReason' => $message,
'errStatus' => '404 - Page not found'
]);
abort(404);
return response()->view('errors.404', [], 404);
} else if ($exception instanceof HttpException && $exception->getStatusCode() == 403) {
$message = 'HTTPResponseException: ' . $exception->getMessage();
Log::error($message);
Expand All @@ -115,7 +115,7 @@ public function render($request, Throwable $exception)
'errReason' => $message,
'errStatus' => '403 - Forbidden'
]);
abort(403);
return response()->view('errors.403', [], 403);
} else if ($exception instanceof HttpException && $exception->getStatusCode() == 419) {
$message = 'HTTPResponseException: ' . $exception->getMessage();
Log::error($message);
Expand All @@ -124,7 +124,7 @@ public function render($request, Throwable $exception)
'errReason' => $message,
'errStatus' => '419 - Page Expired'
]);
abort(419);
return response()->view('errors.419', [], 419);
} else if ($exception instanceof HttpException && $exception->getStatusCode() == 429) {
$message = 'HTTPResponseException: ' . $exception->getMessage();
Log::error($message);
Expand All @@ -133,7 +133,7 @@ public function render($request, Throwable $exception)
'errReason' => $message,
'errStatus' => '429 - Too Many Requests'
]);
abort(429);
return response()->view('errors.429', [], 429);
} else if ($exception instanceof HttpException && $exception->getStatusCode() == 500) {
$message = 'HTTPResponseException: ' . $exception->getMessage();
Log::error($message);
Expand All @@ -142,7 +142,7 @@ public function render($request, Throwable $exception)
'errReason' => $message,
'errStatus' => '500 - Internal Server Error'
]);
abort(500);
return response()->view('errors.500', [], 500);
} else if ($exception instanceof HttpException && $exception->getStatusCode() == 503) {
$message = 'HTTPResponseException: ' . $exception->getMessage();
Log::error($message);
Expand All @@ -151,7 +151,7 @@ public function render($request, Throwable $exception)
'errReason' => $message,
'errStatus' => '503 - Service Temporary Unavailable'
]);
abort(503);
return response()->view('errors.503', [], 503);
}
return parent::render($request, $exception);
}
Expand Down

0 comments on commit f29c30c

Please sign in to comment.