fix: Do no report expired wss auth to error tracker (#13488)

This commit is contained in:
Tom Moor authored and GitHub committed 2026-08-19 08:06:58 -04:00
1 parent 2a9ac3b456
commit 1a1a3398e0
2 files changed
+13 -4

No files matched your search

+11 -2
View File
@@ -13,7 +13,7 @@ import {
FileOperationType,
ImportState,
} from "@shared/types";
import { toError } from "@shared/utils/error";
import { errToId, toError } from "@shared/utils/error";
import type RootStore from "~/stores/RootStore";
import type Collection from "~/models/Collection";
import type Comment from "~/models/Comment";
@@ -47,6 +47,12 @@ type SocketWithAuthentication = Socket & {
authenticated?: boolean;
};
/** Identifiers of socket authentication errors that are expected in normal use. */
const unreportableErrorIds = [
"authentication_required",
"invalid_authentication",
];
export const WebsocketContext = createContext<SocketWithAuthentication | null>(
null
);
@@ -138,7 +144,10 @@ function useConnectionHandlers() {
toast.error(message);
if (message === "No access token") {
// Authentication failures are an expected result of an expired or
// otherwise unusable token, there is nothing to report.
const errorId = errToId(err);
if (errorId && unreportableErrorIds.includes(errorId)) {
return;
}
+2 -2
View File
@@ -5,7 +5,7 @@ import cookie from "cookie";
import type Koa from "koa";
import IO from "socket.io";
import { createAdapter } from "socket.io-redis";
import { errToString, toError } from "@shared/utils/error";
import { errToId, errToString, toError } from "@shared/utils/error";
import env from "@server/env";
import { AuthenticationError } from "@server/errors";
import Logger from "@server/logging/Logger";
@@ -156,7 +156,7 @@ export default function init(
Logger.debug("websockets", `Authentication error socket ${socket.id}`, {
error: message,
});
socket.emit("unauthorized", { message }, function () {
socket.emit("unauthorized", { message, id: errToId(err) }, function () {
socket.disconnect();
});
}