Skip to content

Drop in a screenshot and convert it to clean code (HTML/Tailwind/React/Vue)

Python

handle unknown server error by showing an error message to the user

Abi Raja483d1e2209ad
diff --git a/frontend/src/constants.ts b/frontend/src/constants.ts
index a5da1894..1cc9373a 100644
--- a/frontend/src/constants.ts
+++ b/frontend/src/constants.ts
@@ -1 +1,3 @@
+// WebSocket protocol (RFC 6455) allows for the use of custom close codes in the range 4000-4999
+export const APP_ERROR_WEB_SOCKET_CODE = 4332;
export const USER_CLOSE_WEB_SOCKET_CODE = 4333;
diff --git a/frontend/src/generateCode.ts b/frontend/src/generateCode.ts
index fc408bc8..7fc34e73 100644
--- a/frontend/src/generateCode.ts
+++ b/frontend/src/generateCode.ts
@@ -1,6 +1,9 @@
import toast from "react-hot-toast";
import { WS_BACKEND_URL } from "./config";
-import { USER_CLOSE_WEB_SOCKET_CODE } from "./constants";
+import {
+ APP_ERROR_WEB_SOCKET_CODE,
+ USER_CLOSE_WEB_SOCKET_CODE,
+} from "./constants";
import { FullGenerationSettings } from "./types";
const ERROR_MESSAGE =
@@ -46,8 +49,12 @@ export function generateCode(
if (event.code === USER_CLOSE_WEB_SOCKET_CODE) {
toast.success(CANCEL_MESSAGE);
onCancel();
+ } else if (event.code === APP_ERROR_WEB_SOCKET_CODE) {
+ console.error("Known server error", event);
+ onCancel();
} else if (event.code !== 1000) {
- console.error("WebSocket error code", event);
+ console.error("Unknown server or connection error", event);
+ toast.error(ERROR_MESSAGE);
onCancel();
} else {
onComplete();