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

[Issue #3152] properly error on client for max search term length #3554

Merged
merged 12 commits into from
Jan 22, 2025

Conversation

doug-s-nava
Copy link
Collaborator

@doug-s-nava doug-s-nava commented Jan 16, 2025

Summary

Fixes #3152

Time to review: 20 mins

Changes proposed

Main goal here is to show a helpful error message with a relevant call to action to users when they enter a search term longer than the API allows (100 characters).

To do that this change:

  • introduces client side validation of the query string size, and displays an error on submit click without submitting
  • to handle a case where a request does go out from the client but returns with a validation error (most likely due to a change in API behavior that the client has not yet responded to), the error handling system has been updated to pass relevant information to the client so that it can be handled

This change also fixes a bug that was preventing the search form state to be maintained in the case of an error.

I also observed when doing this work that Next seems to treat the errors thrown by the search fetcher to be unhandled, even though they redirect to the search error page. This means the error toast thing shows up on dev, and the error is logged to the console as unhandled. Is this expected?

Context for reviewers

Test steps for client side validation

  1. start a server on this branch with npm run dev
  2. visit http://localhost:3000/search
  3. enter a search term longer than 99 characters and click submit
  4. VERIFY: search results do not update
  5. VERIFY: an error message is shown (see client validation error screenshot below)
  6. enter a search term less than 99 characters long and submit
  7. VERIFY: search is performed successfully, and error message is removed

Test steps for error response handling

Totally synthetic but the easiest way to do this is to disable the client side check.

  1. comment out lines 23-29 in SearchBar.tsx
  2. enter a search term longer than 99 characters and click submit
  3. VERIFY: page loads with no results and an error message (see server side error screenshot below)
  4. VERIFY: query string is maintained (not cleared) in the search bar

Additional information

Server side error

Screenshot 2025-01-17 at 11 28 07 AM

Client side validation error

Screenshot 2025-01-17 at 12 22 58 PM

@doug-s-nava doug-s-nava changed the title Dschrashun/3152 client max search length [Issue #3152] properly error on client for max search term length Jan 16, 2025
@doug-s-nava doug-s-nava marked this pull request as ready for review January 17, 2025 17:36
@doug-s-nava doug-s-nava force-pushed the dschrashun/3152-client-max-search-length branch from e206b3f to a2d503d Compare January 17, 2025 18:57
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"}`}
Copy link
Collaborator

@acouch acouch Jan 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we do a follow-up to translate this, ie the "adjust your search and try again"?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can make a ticket, but I'm not exactly sure what the scope would need to be. To get this to work as a fully translated UI we'd need to handle translating stuff that's coming from the API, including error messages and our field names. That seems to open up a lot of questions, and since it doesn't seem like we're prioritizing translation right now I don't know when the right time for that conversation is

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant the a search field part.

*/

import { QueryParamData } from "src/types/search/searchRequestTypes";

export interface FrontendErrorDetails {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason not to store this in src/types/... ?

acouch
acouch previously approved these changes Jan 21, 2025
Copy link
Collaborator

@acouch acouch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏿 with a few nit Qs

@doug-s-nava doug-s-nava force-pushed the dschrashun/3152-client-max-search-length branch from 5960572 to 3d0dc4e Compare January 21, 2025 22:21
@doug-s-nava doug-s-nava merged commit 8f6c498 into main Jan 22, 2025
8 checks passed
@doug-s-nava doug-s-nava deleted the dschrashun/3152-client-max-search-length branch January 22, 2025 16:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Handle search max search term length
2 participants