handle unknown server error by showing an error message to the user
This commit is contained in:
parent
29cea327cc
commit
483d1e2209
@ -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;
|
export const USER_CLOSE_WEB_SOCKET_CODE = 4333;
|
||||||
|
|||||||
@ -1,6 +1,9 @@
|
|||||||
import toast from "react-hot-toast";
|
import toast from "react-hot-toast";
|
||||||
import { WS_BACKEND_URL } from "./config";
|
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";
|
import { FullGenerationSettings } from "./types";
|
||||||
|
|
||||||
const ERROR_MESSAGE =
|
const ERROR_MESSAGE =
|
||||||
@ -46,8 +49,12 @@ export function generateCode(
|
|||||||
if (event.code === USER_CLOSE_WEB_SOCKET_CODE) {
|
if (event.code === USER_CLOSE_WEB_SOCKET_CODE) {
|
||||||
toast.success(CANCEL_MESSAGE);
|
toast.success(CANCEL_MESSAGE);
|
||||||
onCancel();
|
onCancel();
|
||||||
|
} else if (event.code === APP_ERROR_WEB_SOCKET_CODE) {
|
||||||
|
console.error("Known server error", event);
|
||||||
|
onCancel();
|
||||||
} else if (event.code !== 1000) {
|
} else if (event.code !== 1000) {
|
||||||
console.error("WebSocket error code", event);
|
console.error("Unknown server or connection error", event);
|
||||||
|
toast.error(ERROR_MESSAGE);
|
||||||
onCancel();
|
onCancel();
|
||||||
} else {
|
} else {
|
||||||
onComplete();
|
onComplete();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user