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:
bbassieandClaude Opus 5.5 committed 2026-10-27 22:03:13 +00:00
1 parent ffe82f81d8
commit 1c7c00b033
37 files changed
+589 -310

No files matched your search

+24 -1
View File
@@ -8,7 +8,8 @@ import * as role from "../data/messages_role.js";
import * as note from "../data/messages_note.js";
import * as plugin from "../data/messages_plugin.js";
import * as subscriptions from "../subscriptions.js";
import type { RequestClass, EventClass } from "./link.js";
import * as errors from "../errors.js";
import type { RequestClass, EventClass, ErrorClass } from "./link.js";
/**
* Event and Request payloads registered with the Link class. Used to decode
@@ -151,3 +152,25 @@ export const dataClasses: (RequestClass<unknown, unknown> | EventClass<unknown>)
plugin.PluginLatestVersionsRequest,
plugin.UpdateAllRequest,
];
/**
* Error classes registered with the Link class. Used to send errors thrown
* by request handlers back as instances of the same class.
* @internal
*/
export const errorClasses: ErrorClass[] = [
errors.ClientError,
errors.ValidationError,
errors.InvalidValueError,
errors.InvalidFieldError,
errors.ForbiddenError,
errors.PermissionDeniedError,
errors.InvalidAccessError,
errors.NotFoundError,
errors.TimeoutError,
errors.ConflictError,
errors.ServerError,
errors.InternalServerError,
errors.InvalidMessage,
errors.SessionLost,
];