-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* removes global state * removes search error page * instead of a boundary based approach, which is limited to client components, handles API request based search errors where they occur
- Loading branch information
1 parent
040057d
commit d3936ca
Showing
15 changed files
with
81 additions
and
316 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
"use client"; | ||
|
||
import { ParsedError } from "src/types/generalTypes"; | ||
import { ErrorProps } from "src/types/uiTypes"; | ||
|
||
import { useTranslations } from "next-intl"; | ||
import { Alert } from "@trussworks/react-uswds"; | ||
|
||
import ServerErrorAlert from "src/components/ServerErrorAlert"; | ||
|
||
function isValidJSON(str: string) { | ||
try { | ||
JSON.parse(str); | ||
return true; | ||
} catch (e) { | ||
return false; // String is not valid JSON | ||
} | ||
} | ||
|
||
export function SearchError({ error }: ErrorProps) { | ||
const t = useTranslations("Search"); | ||
|
||
const parsedErrorData = isValidJSON(error.message) | ||
? (JSON.parse(error.message) as ParsedError) | ||
: {}; | ||
|
||
// note that the validation error will contain untranslated strings | ||
// and will only appear in development, prod builds will not include user facing error details | ||
const ErrorAlert = | ||
parsedErrorData.details && parsedErrorData.type === "ValidationError" ? ( | ||
<Alert type="error" heading={t("validationError")} headingLevel="h4"> | ||
{`Error in ${parsedErrorData.details.field || "a search field"}: ${parsedErrorData.details.message || "adjust your search and try again"}`} | ||
</Alert> | ||
) : ( | ||
<ServerErrorAlert callToAction={t("generic_error_cta")} /> | ||
); | ||
|
||
return <div className="tablet:grid-col-8">{ErrorAlert}</div>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.