Skip to content

Commit

Permalink
refactor(middleware): replace _label with success property in mid…
Browse files Browse the repository at this point in the history
…dleware result
  • Loading branch information
TheEdoRan committed Mar 27, 2024
1 parent 0e48f3a commit c1ab349
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion packages/next-safe-action/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class SafeActionClient<const Ctx = null> {
return async (clientInput: unknown) => {
let prevCtx: any = null;
let frameworkError: Error | undefined = undefined;
const middlewareResult: MiddlewareResult<any> = { __label: Symbol("MiddlewareResult") };
const middlewareResult: MiddlewareResult<any> = { success: false };

// Execute the middleware stack.
const executeMiddlewareChain = async (idx = 0) => {
Expand Down Expand Up @@ -126,13 +126,15 @@ class SafeActionClient<const Ctx = null> {
}

const data = (await serverCodeFn(parsedInput.data, prevCtx)) ?? null;
middlewareResult.success = true;
middlewareResult.data = data;
middlewareResult.parsedInput = parsedInput.data;
}
} catch (e: unknown) {
// next/navigation functions work by throwing an error that will be
// processed internally by Next.js.
if (isRedirectError(e) || isNotFoundError(e)) {
middlewareResult.success = true;
frameworkError = e;
return;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/next-safe-action/src/index.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export type SafeAction<S extends Schema, Data> = (
export type MiddlewareResult<NextCtx> = SafeActionResult<any, unknown, NextCtx> & {
parsedInput?: unknown;
ctx?: unknown;
__label: Symbol;
success: boolean;
};

/**
Expand Down

0 comments on commit c1ab349

Please sign in to comment.