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

+61 -25
View File
@@ -18,40 +18,76 @@ export class InstallationError extends Error {
}
/**
* Thrown from requests sent when an error occured handling it
* Base class for errors caused by the request, such as invalid input,
* missing permissions or a missing resource. Corresponds to the HTTP 4xx
* range.
*
* Link does not log these as unexpected when a request handler throws them.
*/
export class RequestError extends Error {
constructor(
message: string,
public code = "RequestError",
public stack?: string,
) {
super(message);
}
}
export class ClientError extends Error { }
/**
* Thrown when a permission check fails.
*
* Is a subclass of RequestError to prevent logging stack traces when
* requests fail due to permission denied.
*
* Thrown when the request contains invalid data (HTTP 400)
*/
export class PermissionError extends RequestError {
constructor(
message: string,
code = "PermissionError",
stack?: string,
) {
super(message, code, stack);
}
export class ValidationError extends ClientError { }
}
/**
* Thrown when a config value cannot be used for its field
*/
export class InvalidValueError extends ValidationError { }
/**
* Thrown when a config field does not exist
*/
export class InvalidFieldError extends ValidationError { }
/**
* Thrown when the request is not allowed (HTTP 403)
*/
export class ForbiddenError extends ClientError { }
/**
* Thrown when a permission check fails
*/
export class PermissionDeniedError extends ForbiddenError { }
/**
* Thrown when a config field is not accessible from the current location
*/
export class InvalidAccessError extends ForbiddenError { }
/**
* Thrown when a resource the request refers to does not exist (HTTP 404)
*/
export class NotFoundError extends ClientError { }
/**
* Thrown when an operation for a request timed out (HTTP 408)
*/
export class TimeoutError extends ClientError { }
/**
* Thrown when the request conflicts with the current state, such as an
* instance that is running or a host that is not connected (HTTP 409)
*/
export class ConflictError extends ClientError { }
/**
* Base class for errors caused by the side handling the request.
* Corresponds to the HTTP 5xx range.
*/
export class ServerError extends Error { }
/**
* Received in place of an error response whose class is not registered,
* such as a TypeError thrown by a request handler (HTTP 500)
*/
export class InternalServerError extends ServerError { }
/**
* Signal for messages that fail validation
*/
export class InvalidMessage extends Error {
export class InvalidMessage extends ValidationError {
code = "InvalidMessage";
constructor(
message: string,