Skip to content

Commit

Permalink
rename ensureError function to convertToError
Browse files Browse the repository at this point in the history
  • Loading branch information
AbanoubGhadban committed Oct 31, 2024
1 parent 721fed8 commit f36d74d
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions node_package/src/serverRenderReactComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type RenderOptions = {
renderingReturnsPromises: boolean;
};

function ensureError(e: unknown): Error {
function convertToError(e: unknown): Error {
return e instanceof Error ? e : new Error(String(e));
}

Expand Down Expand Up @@ -96,7 +96,7 @@ function handleRenderingError(e: unknown, options: { componentName: string, thro
if (options.throwJsErrors) {
throw e;
}
const error = ensureError(e);
const error = convertToError(e);
return {
hasErrors: true,
result: handleError({ e: error, name: options.componentName, serverSide: true }),
Expand Down Expand Up @@ -266,7 +266,7 @@ const streamRenderReactComponent = (reactRenderingResult: ReactElement, options:

const renderingStream = ReactDOMServer.renderToPipeableStream(reactRenderingResult, {
onShellError(e) {
const error = ensureError(e);
const error = convertToError(e);
renderState.hasErrors = true;
renderState.error = error;

Expand All @@ -286,7 +286,7 @@ const streamRenderReactComponent = (reactRenderingResult: ReactElement, options:
if (!renderState.isShellReady) {
return;
}
const error = ensureError(e);
const error = convertToError(e);
if (throwJsErrors) {
emitError(error);
}
Expand Down Expand Up @@ -323,7 +323,7 @@ export const streamServerRenderedReactComponent = (options: RenderParams): Reada
throw e;
}

const error = ensureError(e);
const error = convertToError(e);
const htmlResult = handleError({ e: error, name: componentName, serverSide: true });
const jsonResult = JSON.stringify(createResultObject(htmlResult, buildConsoleReplay(), { hasErrors: true, error, result: null }));
return stringToStream(jsonResult);
Expand Down

0 comments on commit f36d74d

Please sign in to comment.