@rivetkit/core
Version:
315 lines (279 loc) • 10.1 kB
JavaScript
;Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } var _class;// 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 = class extends Error {
constructor(code, message, opts) {
super(message, { cause: opts == null ? void 0 : opts.cause });_class.prototype.__init.call(this);_class.prototype.__init2.call(this);;
this.code = code;
this.public = _nullishCoalesce((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;
}
}
__init() {this.__type = "ActorError"}
__init2() {this.statusCode = 500}
static isActorError(error) {
return typeof error === "object" && error.__type === "ActorError";
}
toString() {
return this.message;
}
/**
* Serialize error for HTTP response
*/
serializeForHttp() {
return {
type: this.code,
message: this.message,
metadata: this.metadata
};
}
}, _class);
var InternalError = class extends ActorError {
constructor(message) {
super(INTERNAL_ERROR_CODE, message);
}
};
var Unreachable = class extends InternalError {
constructor(x) {
super(`Unreachable case: ${x}`);
}
};
var StateNotEnabled = class extends ActorError {
constructor() {
super(
"state_not_enabled",
"State not enabled. Must implement `createState` or `state` to use state. (https://www.rivet.gg/docs/actors/state/#initializing-state)"
);
}
};
var ConnStateNotEnabled = class extends ActorError {
constructor() {
super(
"conn_state_not_enabled",
"Connection state not enabled. Must implement `createConnectionState` or `connectionState` to use connection state. (https://www.rivet.gg/docs/actors/connections/#connection-state)"
);
}
};
var VarsNotEnabled = class extends ActorError {
constructor() {
super(
"vars_not_enabled",
"Variables not enabled. Must implement `createVars` or `vars` to use state. (https://www.rivet.gg/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(
"invalid_encoding",
`Invalid encoding \`${format}\`. (https://www.rivet.gg/docs/actors/clients/#actor-client)`,
{
public: true
}
);
}
};
var ConnNotFound = class extends ActorError {
constructor(id) {
super("conn_not_found", `Connection not found for ID: ${id}`, {
public: true
});
}
};
var IncorrectConnToken = class extends ActorError {
constructor() {
super("incorrect_conn_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.runServer({ maxIncomingMessageSize: ... })`",
{ public: true }
);
}
};
var MalformedMessage = class extends ActorError {
constructor(cause) {
super("malformed_message", `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.gg/docs/actors/state/#limitations)";
super("invalid_state_type", msg);
}
};
var Unsupported = class extends ActorError {
constructor(feature) {
super("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(_nullishCoalesce((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("invalid_query_json", `Invalid query JSON: ${error}`, {
public: true,
cause: error
});
}
};
var InvalidRequest = class extends ActorError {
constructor(error) {
super("invalid_request", `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.gg/docs/actors/clients/#actor-client)` : "Actor not found (https://www.rivet.gg/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.gg/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("invalid_action_request", message, { public: true });
}
};
var InvalidParams = class extends ActorError {
constructor(message) {
super("invalid_params", message, { public: true });
}
};
var Unauthorized = class extends ActorError {
constructor(message) {
super(
"unauthorized",
_nullishCoalesce(message, () => ( "Unauthorized. Access denied. (https://www.rivet.gg/docs/actors/authentication/)")),
{
public: true
}
);
this.statusCode = 401;
}
};
var Forbidden = class extends ActorError {
constructor(message, opts) {
super(
"forbidden",
_nullishCoalesce(message, () => ( "Forbidden. Access denied. (https://www.rivet.gg/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(
"fetch_handler_not_defined",
"Raw HTTP handler not defined. Actor must implement `onFetch` to handle raw HTTP requests. (https://www.rivet.gg/docs/actors/fetch-and-websocket-handler/)",
{ public: true }
);
this.statusCode = 404;
}
};
var WebSocketHandlerNotDefined = class extends ActorError {
constructor() {
super(
"websocket_handler_not_defined",
"Raw WebSocket handler not defined. Actor must implement `onWebSocket` to handle raw WebSocket connections. (https://www.rivet.gg/docs/actors/fetch-and-websocket-handler/)",
{ public: true }
);
this.statusCode = 404;
}
};
var InvalidFetchResponse = class extends ActorError {
constructor() {
super(
"invalid_fetch_response",
"Actor's onFetch handler must return a Response object. Returning void/undefined is not allowed. (https://www.rivet.gg/docs/actors/fetch-and-websocket-handler/)",
{ public: true }
);
this.statusCode = 500;
}
};
exports.INTERNAL_ERROR_CODE = INTERNAL_ERROR_CODE; exports.INTERNAL_ERROR_DESCRIPTION = INTERNAL_ERROR_DESCRIPTION; exports.USER_ERROR_CODE = USER_ERROR_CODE; exports.ActorError = ActorError; exports.InternalError = InternalError; exports.Unreachable = Unreachable; exports.StateNotEnabled = StateNotEnabled; exports.ConnStateNotEnabled = ConnStateNotEnabled; exports.VarsNotEnabled = VarsNotEnabled; exports.ActionTimedOut = ActionTimedOut; exports.ActionNotFound = ActionNotFound; exports.InvalidEncoding = InvalidEncoding; exports.ConnNotFound = ConnNotFound; exports.IncorrectConnToken = IncorrectConnToken; exports.MessageTooLong = MessageTooLong; exports.MalformedMessage = MalformedMessage; exports.InvalidStateType = InvalidStateType; exports.Unsupported = Unsupported; exports.UserError = UserError; exports.InvalidQueryJSON = InvalidQueryJSON; exports.InvalidRequest = InvalidRequest; exports.ActorNotFound = ActorNotFound; exports.ActorAlreadyExists = ActorAlreadyExists; exports.ProxyError = ProxyError; exports.InvalidActionRequest = InvalidActionRequest; exports.InvalidParams = InvalidParams; exports.Unauthorized = Unauthorized; exports.Forbidden = Forbidden; exports.DatabaseNotEnabled = DatabaseNotEnabled; exports.FetchHandlerNotDefined = FetchHandlerNotDefined; exports.WebSocketHandlerNotDefined = WebSocketHandlerNotDefined; exports.InvalidFetchResponse = InvalidFetchResponse;
//# sourceMappingURL=chunk-53LWTTEX.cjs.map