Skip to content

Commit

Permalink
fix(): make new error class instead of use cause
Browse files Browse the repository at this point in the history
for compatibility
  • Loading branch information
weareoutman committed Oct 20, 2023
1 parent 9dba3e0 commit c2bc094
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
20 changes: 17 additions & 3 deletions packages/brick-kit/src/core/FlowApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ export async function getArgsOfCustomApi(
: (await _internalApiGetMicroAppApiOrchestrationMap()).get(provider);

if (!apiDefinition) {
throw new Error(
`${isFlowApi ? "Flow" : "Legacy Custom"} API not found: "${provider}"`,
{ cause: "FLOW_API_NOT_FOUND" }
throw new FlowApiNotFoundError(
`${isFlowApi ? "Flow" : "Legacy Custom"} API not found: "${provider}"`
);
}

Expand Down Expand Up @@ -198,3 +197,18 @@ async function fetchFlowApiDefinitionFromRemote(
}
: null;
}

class FlowApiNotFoundError extends Error {
constructor(message: string) {
// Pass remaining arguments (including vendor specific ones) to parent constructor
super(message);

this.name = "FlowApiNotFoundError";

// Maintains proper stack trace for where our error was thrown (only available on V8)
// istanbul ignore else
if (Error.captureStackTrace) {
Error.captureStackTrace(this, FlowApiNotFoundError);
}
}
}
6 changes: 3 additions & 3 deletions packages/brick-kit/src/core/StoryboardContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,10 @@ export class StoryboardContextWrapper {
const shouldDismiss = (error: unknown): boolean => {
// If render twice immediately, flow API contracts maybe cleared before
// the second rendering, while the page load handlers of the first
// rendering can't be cancelled, which causes `FLOW_API_NOT_FOUND`. So
// we ignore error reporting for this case.
// rendering can't be cancelled, which throws `FlowApiNotFoundError`.
// So we ignore error reporting for this case.
return (
(error as Error)?.cause === "FLOW_API_NOT_FOUND" &&
(error as Error)?.name === "FlowApiNotFoundError" &&
this.renderId &&
this.renderId !== _internalApiGetRouterRenderId()
);
Expand Down

0 comments on commit c2bc094

Please sign in to comment.