diff --git a/frontend/spa/src/WrongPlatformError.vue b/frontend/spa/src/WrongPlatformError.vue
new file mode 100644
index 0000000..8d32b65
--- /dev/null
+++ b/frontend/spa/src/WrongPlatformError.vue
@@ -0,0 +1,19 @@
+
+
+
+
+
+
Магазин работает только внутри Telegram.
+
+
+
+
+
+
+
diff --git a/frontend/spa/src/errors.js b/frontend/spa/src/errors.js
new file mode 100644
index 0000000..82eec4a
--- /dev/null
+++ b/frontend/spa/src/errors.js
@@ -0,0 +1,30 @@
+class AppError extends Error {
+ constructor(message, code = 'APP_ERROR') {
+ super(message);
+ this.name = this.constructor.name;
+ this.code = code;
+
+ // важно для наследования Error
+ if (Error.captureStackTrace) {
+ Error.captureStackTrace(this, this.constructor);
+ }
+ }
+}
+
+class MaintenanceError extends AppError {
+ constructor(message = 'Application is under maintenance') {
+ super(message, 'MAINTENANCE');
+ }
+}
+
+class TelegramInitDataError extends AppError {
+ constructor(message = 'Application must be opened inside Telegram') {
+ super(message, 'NO_INIT_DATA');
+ }
+}
+
+export {
+ AppError,
+ MaintenanceError,
+ TelegramInitDataError,
+};
diff --git a/frontend/spa/src/main.js b/frontend/spa/src/main.js
index 02683e2..a654310 100644
--- a/frontend/spa/src/main.js
+++ b/frontend/spa/src/main.js
@@ -21,6 +21,8 @@ import {defaultConfig, plugin} from '@formkit/vue';
import config from './formkit.config.js';
import {TC_PULSE_EVENTS} from "@/constants/tPulseEvents.js";
import {usePulseStore} from "@/stores/Pulse.js";
+import {TelegramInitDataError} from '@/errors.js';
+import WrongPlatformError from "@/WrongPlatformError.vue";
register();
@@ -41,7 +43,7 @@ const appLoading = createApp(AppLoading);
appLoading.mount('#app');
function setTelegramUIColors() {
- const daisyUIBgColor = getCssVarOklchRgb('--color-base-100');
+ const daisyUIBgColor = getCssVarOklchRgb('--color-base-200');
window.Telegram.WebApp.setHeaderColor(daisyUIBgColor);
window.Telegram.WebApp.setBackgroundColor(daisyUIBgColor);
}
@@ -56,7 +58,7 @@ settings.load()
.then(() => settings.ya_metrika_enabled && injectYaMetrika())
.then(() => {
if (! window.Telegram.WebApp.initData) {
- throw new Error('Invalid init data. Application not in Telegram View');
+ throw new TelegramInitDataError('Invalid init data. Application not in Telegram View');
}
})
.then(() => pulse.initFromStartParams())
@@ -113,7 +115,18 @@ settings.load()
})
.then(() => window.Telegram.WebApp.ready())
.catch(error => {
- console.error(error);
- const errorApp = createApp(ApplicationError, {error});
+ const code = error.code ?? error.response._data.code;
+ let ErrorComponent;
+
+ switch (code) {
+ case 'NO_INIT_DATA':
+ ErrorComponent = WrongPlatformError;
+ break;
+
+ default:
+ ErrorComponent = ApplicationError;
+ }
+
+ const errorApp = createApp(ErrorComponent, { error });
errorApp.mount('#app-error');
});
diff --git a/module/oc_telegram_shop/upload/oc_telegram_shop/src/Exceptions/CustomExceptionHandler.php b/module/oc_telegram_shop/upload/oc_telegram_shop/src/Exceptions/CustomExceptionHandler.php
index ddd2303..7c7b670 100755
--- a/module/oc_telegram_shop/upload/oc_telegram_shop/src/Exceptions/CustomExceptionHandler.php
+++ b/module/oc_telegram_shop/upload/oc_telegram_shop/src/Exceptions/CustomExceptionHandler.php
@@ -14,7 +14,10 @@ class CustomExceptionHandler implements ExceptionHandlerInterface
public function respond(Throwable $exception): ?JsonResponse
{
if ($exception instanceof TelegramInvalidSignatureException) {
- return new JsonResponse(['error' => 'Invalid Signature'], Response::HTTP_BAD_REQUEST);
+ return new JsonResponse([
+ 'error' => 'Invalid Signature',
+ 'code' => 'NO_INIT_DATA',
+ ], Response::HTTP_BAD_REQUEST);
}
return null;