Skip to content

Commit

Permalink
Return undefined on 404
Browse files Browse the repository at this point in the history
Signed-off-by: Marcos Candeia <[email protected]>
  • Loading branch information
mcandeia committed Oct 19, 2024
1 parent fe64b50 commit a32c39e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/actors/proxyutil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,9 @@ export const createHttpInvoker = <
},
);
if (!resp.ok) {
if (resp.status === 404) {
return undefined;
}
const constructorName = resp.headers.get(ACTOR_CONSTRUCTOR_NAME_HEADER);
const ErrorConstructor =
options?.errorHandling?.[constructorName ?? "Error"] ?? Error;
Expand Down
11 changes: 10 additions & 1 deletion src/actors/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ export interface ActorInstance {
initialization: Promise<void>;
}

const KNOWN_METHODS: Record<string, symbol> = {
"Symbol(Symbol.asyncDispose)": Symbol.asyncDispose,
"Symbol(Symbol.dispose)": Symbol.dispose,
};
/**
* Represents the runtime for managing and invoking actors.
*/
Expand All @@ -94,12 +98,17 @@ export class ActorRuntime {
constructor(
protected actorsConstructors: Array<ActorConstructor>,
) {
const invoke: ActorInvoker["invoke"] = async (actorName, method, args) => {
const invoke: ActorInvoker["invoke"] = async (
actorName,
methodName,
args,
) => {
const actorInvoker = actorName ? this.actors.get(actorName) : undefined;
if (!actorInvoker) {
throw new ActorError(`actor ${actorName} not found`, "NOT_FOUND");
}
const { actor, initialization } = actorInvoker;
const method = KNOWN_METHODS[methodName] ?? methodName;
if (!(method in actor)) {
throw new ActorError(
`actor ${actorName} not found`,
Expand Down

0 comments on commit a32c39e

Please sign in to comment.