Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

usePageErrors hook adds non-string objects to array #67

Open
brandongregoryscott opened this issue Apr 6, 2021 · 0 comments · May be fixed by #88
Open

usePageErrors hook adds non-string objects to array #67

brandongregoryscott opened this issue Apr 6, 2021 · 0 comments · May be fixed by #88
Labels
bug Something isn't working

Comments

@brandongregoryscott
Copy link
Contributor

The usePageErrors hook correctly checks the result as an instance of a ResultRecord to pull out error messages and returns early. However, result can come from anywhere - in cases where it is an Error thrown, the array that we are returning as pageErrors is no longer a string array - it might be a [Error, string] or objects of any other shape. This can cause issues when mapping out what consumers expect to be an array of plain strings to JSX.

Example of React error in development when an Error is thrown and caught by handlePageLoadError, then mapped in an unordered list

image

Add a safe guard to check for a string or otherwise try to coalesce the object into a string:

if (typeof result === "string") {
    setPageErrors((errors: string[]) => [...errors, result]);
    return;
}

setPageErrors((errors: string[]) => [...errors, result.toString()]);
@brandongregoryscott brandongregoryscott added the bug Something isn't working label Apr 6, 2021
@dylanjustice dylanjustice linked a pull request Jun 22, 2021 that will close this issue
9 tasks
@dylanjustice dylanjustice linked a pull request Jun 22, 2021 that will close this issue
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant