mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-22 08:13:12 +09:00
Keep error classes across links
Error responses now carry the registered name of the thrown error's class, and the requester rejects with an instance of that class instead of a generic RequestError. Error classes are registered like message classes, and plugins list their own in `errors`. RequestError is replaced by a hierarchy following the HTTP status codes: ClientError (ValidationError, ForbiddenError, NotFoundError, TimeoutError, ConflictError) and ServerError (InternalServerError). PermissionError is PermissionDeniedError and the config errors InvalidValue, InvalidField and InvalidAccess gain an Error suffix. Link logs only errors whose class is not registered. These arrive on the other side as InternalServerError with the original message and stack, so an error forwarded through the controller is logged once, where it was thrown. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ffe82f81d8
commit
1c7c00b033
37 files changed
+589
-310
No files matched your search
@@ -3,7 +3,7 @@ import { Link, Event, EventClass, RequestHandler, WebSocketBaseConnector } from
|
||||
import { Address, MessageRequest, IUser, JsonBoolean, StringEnum } from "./data/index.js";
|
||||
import isDeepStrictEqual from "#is_deep_strict_equal";
|
||||
import type { PermissionName } from "./permissions.js";
|
||||
import { RequestError } from "./errors.js";
|
||||
import { SessionLost, ValidationError } from "./errors.js";
|
||||
import { logger } from "./logging.js";
|
||||
|
||||
export type SubscriptionRequestHandler<T> = RequestHandler<SubscriptionRequest, Event<T> | null>;
|
||||
@@ -351,7 +351,7 @@ export class SubscriptionController {
|
||||
}
|
||||
}
|
||||
if (count > this._maxFilters) {
|
||||
throw new RequestError(`Subscription exceeds the limit of ${this._maxFilters} filters`);
|
||||
throw new ValidationError(`Subscription exceeds the limit of ${this._maxFilters} filters`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -685,7 +685,7 @@ export class EventSubscriber<E, S = null> {
|
||||
this._notify(null);
|
||||
}
|
||||
} catch (err: any) {
|
||||
if (!(err instanceof RequestError) || err.code !== "SessionLost") {
|
||||
if (!(err instanceof SessionLost)) {
|
||||
logger.error(`Unexpected error updating ${entry.name} subscription:\n${err.stack}`);
|
||||
}
|
||||
if (err instanceof Error) {
|
||||
|
||||
Reference in new issue
Block a user