UNPKG

rivetkit

Version:

Lightweight libraries for building stateful actors on edge platforms

374 lines (373 loc) 10.1 kB
// src/actor/errors.ts var INTERNAL_ERROR_CODE = "internal_error"; var INTERNAL_ERROR_DESCRIPTION = "Internal error. Read the server logs for more details."; var USER_ERROR_CODE = "user_error"; var ActorError = class extends Error { __type = "ActorError"; public; metadata; statusCode = 500; group; code; static isActorError(error) { return typeof error === "object" && error.__type === "ActorError"; } constructor(group, code, message, opts) { super(message, { cause: opts == null ? void 0 : opts.cause }); this.group = group; this.code = code; this.public = (opts == null ? void 0 : opts.public) ?? false; this.metadata = opts == null ? void 0 : opts.metadata; if (opts == null ? void 0 : opts.public) { this.statusCode = 400; } } toString() { return this.message; } /** * Serialize error for HTTP response */ serializeForHttp() { return { type: this.code, message: this.message, metadata: this.metadata }; } }; var InternalError = class extends ActorError { constructor(message) { super("actor", INTERNAL_ERROR_CODE, message); } }; var Unreachable = class extends InternalError { constructor(x) { super(`Unreachable case: ${x}`); } }; var StateNotEnabled = class extends ActorError { constructor() { super( "actor", "state_not_enabled", "State not enabled. Must implement `createState` or `state` to use state. (https://www.rivet.dev/docs/actors/state/#initializing-state)" ); } }; var ConnStateNotEnabled = class extends ActorError { constructor() { super( "actor", "conn_state_not_enabled", "Connection state not enabled. Must implement `createConnectionState` or `connectionState` to use connection state. (https://www.rivet.dev/docs/actors/connections/#connection-state)" ); } }; var VarsNotEnabled = class extends ActorError { constructor() { super( "actor", "vars_not_enabled", "Variables not enabled. Must implement `createVars` or `vars` to use state. (https://www.rivet.dev/docs/actors/ephemeral-variables/#initializing-variables)" ); } }; var ActionTimedOut = class extends ActorError { constructor() { super( "action", "timed_out", "Action timed out. This can be increased with: `actor({ options: { action: { timeout: ... } } })`", { public: true } ); } }; var ActionNotFound = class extends ActorError { constructor(name) { super( "action", "not_found", `Action '${name}' not found. Validate the action exists on your actor.`, { public: true } ); } }; var InvalidEncoding = class extends ActorError { constructor(format) { super( "encoding", "invalid", `Invalid encoding \`${format}\`. (https://www.rivet.dev/docs/actors/clients/#actor-client)`, { public: true } ); } }; var ConnNotFound = class extends ActorError { constructor(id) { super("connection", "not_found", `Connection not found for ID: ${id}`, { public: true }); } }; var IncorrectConnToken = class extends ActorError { constructor() { super("connection", "incorrect_token", "Incorrect connection token.", { public: true }); } }; var MessageTooLong = class extends ActorError { constructor() { super( "message", "too_long", "Message too long. This can be configured with: `registry.start({ maxIncomingMessageSize: ... })`", { public: true } ); } }; var MalformedMessage = class extends ActorError { constructor(cause) { super("message", "malformed", `Malformed message: ${cause}`, { public: true, cause }); } }; var InvalidStateType = class extends ActorError { constructor(opts) { let msg = ""; if (opts == null ? void 0 : opts.path) { msg += `Attempted to set invalid state at path \`${opts.path}\`.`; } else { msg += "Attempted to set invalid state."; } msg += " Valid types include: null, undefined, boolean, string, number, BigInt, Date, RegExp, Error, typed arrays (Uint8Array, Int8Array, Float32Array, etc.), Map, Set, Array, and plain objects. (https://www.rivet.dev/docs/actors/state/#limitations)"; super("state", "invalid_type", msg); } }; var Unsupported = class extends ActorError { constructor(feature) { super("feature", "unsupported", `Unsupported feature: ${feature}`); } }; var UserError = class extends ActorError { /** * Constructs a new UserError instance. * * @param message - The error message to be displayed. * @param opts - Optional parameters for the error, including a machine-readable code and additional metadata. */ constructor(message, opts) { super("user", (opts == null ? void 0 : opts.code) ?? USER_ERROR_CODE, message, { public: true, metadata: opts == null ? void 0 : opts.metadata }); } }; var InvalidQueryJSON = class extends ActorError { constructor(error) { super("request", "invalid_query_json", `Invalid query JSON: ${error}`, { public: true, cause: error }); } }; var InvalidRequest = class extends ActorError { constructor(error) { super("request", "invalid", `Invalid request: ${error}`, { public: true, cause: error }); } }; var ActorNotFound = class extends ActorError { constructor(identifier) { super( "actor", "not_found", identifier ? `Actor not found: ${identifier} (https://www.rivet.dev/docs/actors/clients/#actor-client)` : "Actor not found (https://www.rivet.dev/docs/actors/clients/#actor-client)", { public: true } ); } }; var ActorAlreadyExists = class extends ActorError { constructor(name, key) { super( "actor", "already_exists", `Actor already exists with name '${name}' and key '${JSON.stringify(key)}' (https://www.rivet.dev/docs/actors/clients/#actor-client)`, { public: true } ); } }; var ProxyError = class extends ActorError { constructor(operation, error) { super( "proxy", "error", `Error proxying ${operation}, this is likely an internal error: ${error}`, { public: true, cause: error } ); } }; var InvalidActionRequest = class extends ActorError { constructor(message) { super("action", "invalid_request", message, { public: true }); } }; var InvalidParams = class extends ActorError { constructor(message) { super("params", "invalid", message, { public: true }); } }; var Unauthorized = class extends ActorError { constructor(message) { super( "auth", "unauthorized", message ?? "Unauthorized. Access denied. (https://www.rivet.dev/docs/actors/authentication/)", { public: true } ); this.statusCode = 401; } }; var Forbidden = class extends ActorError { constructor(message, opts) { super( "auth", "forbidden", message ?? "Forbidden. Access denied. (https://www.rivet.dev/docs/actors/authentication/)", { public: true, metadata: opts == null ? void 0 : opts.metadata } ); this.statusCode = 403; } }; var DatabaseNotEnabled = class extends ActorError { constructor() { super( "database", "not_enabled", "Database not enabled. Must implement `database` to use database." ); } }; var FetchHandlerNotDefined = class extends ActorError { constructor() { super( "handler", "fetch_not_defined", "Raw HTTP handler not defined. Actor must implement `onFetch` to handle raw HTTP requests. (https://www.rivet.dev/docs/actors/fetch-and-websocket-handler/)", { public: true } ); this.statusCode = 404; } }; var WebSocketHandlerNotDefined = class extends ActorError { constructor() { super( "handler", "websocket_not_defined", "Raw WebSocket handler not defined. Actor must implement `onWebSocket` to handle raw WebSocket connections. (https://www.rivet.dev/docs/actors/fetch-and-websocket-handler/)", { public: true } ); this.statusCode = 404; } }; var InvalidFetchResponse = class extends ActorError { constructor() { super( "handler", "invalid_fetch_response", "Actor's onFetch handler must return a Response object. Returning void/undefined is not allowed. (https://www.rivet.dev/docs/actors/fetch-and-websocket-handler/)", { public: true } ); this.statusCode = 500; } }; var MissingActorHeader = class extends ActorError { constructor() { super( "request", "missing_actor_header", "Missing x-rivet-actor header when x-rivet-target=actor", { public: true } ); this.statusCode = 400; } }; var WebSocketsNotEnabled = class extends ActorError { constructor() { super( "driver", "websockets_not_enabled", "WebSockets are not enabled for this driver", { public: true } ); this.statusCode = 400; } }; var FeatureNotImplemented = class extends ActorError { constructor(feature) { super("feature", "not_implemented", `${feature} is not implemented`, { public: true }); this.statusCode = 501; } }; var RouteNotFound = class extends ActorError { constructor() { super("route", "not_found", "Route not found", { public: true }); this.statusCode = 404; } }; export { INTERNAL_ERROR_CODE, INTERNAL_ERROR_DESCRIPTION, USER_ERROR_CODE, ActorError, InternalError, Unreachable, StateNotEnabled, ConnStateNotEnabled, VarsNotEnabled, ActionTimedOut, ActionNotFound, InvalidEncoding, ConnNotFound, IncorrectConnToken, MessageTooLong, MalformedMessage, InvalidStateType, Unsupported, UserError, InvalidQueryJSON, InvalidRequest, ActorNotFound, ActorAlreadyExists, ProxyError, InvalidActionRequest, InvalidParams, Unauthorized, Forbidden, DatabaseNotEnabled, FetchHandlerNotDefined, WebSocketHandlerNotDefined, InvalidFetchResponse, MissingActorHeader, WebSocketsNotEnabled, FeatureNotImplemented, RouteNotFound }; //# sourceMappingURL=chunk-YPZFLUO6.js.map