Skip to content

feat(general): add 404 error page #148

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

Open
wants to merge 38 commits into
base: release/v0.2
Choose a base branch
from

Conversation

chlongng
Copy link

@chlongng chlongng commented Apr 17, 2025

Summary by CodeRabbit

  • New Features
    • Introduced flexible error layout components with customizable slots for title, subtitle, button, and containers.
    • Added a dedicated "Not Found" (404) error page with localized messages.
  • Documentation
    • Added a new guide on error handling and usage of the error layout components.
    • Updated sidebar navigation to include the new error handling documentation.
  • Bug Fixes
    • Improved error display logic for better handling of 404 and general errors.
  • Style
    • Added localized button labels for error pages in English and German.

aheartforspinach and others added 30 commits February 26, 2025 14:32
# Conflicts:
#	.env.example
#	i18n/locales/de-DE/error.json
#	i18n/locales/en-GB/error.json
…12-cms-pages

# Conflicts:
#	.env.example
#	bun.lock
#	composables/usePondCmsUtils.ts
#	docs/.vitepress/config.ts
#	nuxt.config.ts
#	package.json
#	pages/[...all].vue
#	tailwind.config.js
…feature/POND-14-404-error

# Conflicts:
#	bun.lock
#	package.json
…12-cms-pages

# Conflicts:
#	bun.lock
#	package.json
…feature/POND-14-404-error

# Conflicts:
#	bun.lock
#	package.json
Base automatically changed from feature/POND-12-cms-pages to release/v0.2 May 6, 2025 12:38
…14-404-error

# Conflicts:
#	docs/.vitepress/config.ts
#	error.vue
#	i18n/locales/de-DE/error.json
#	i18n/locales/en-GB/error.json
#	nuxt.config.ts
Copy link

coderabbitai bot commented May 15, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

This update introduces a modular error handling system for a Vue application. It adds new error layout and not-found components with customizable slots, updates error display logic to use these components, and provides localized button labels. Documentation and navigation for error handling are also included in the project's docs.

Changes

File(s) Change Summary
components/error/ErrorLayout.vue, components/error/ErrorLayoutInner.vue Added new error layout components with named slots for wrapper, container, title, subTitle, and button, enabling flexible error page customization.
components/error/ErrorNotFound.vue, components/error/ErrorNotFoundInner.vue Introduced not-found error components using the new error layout, with localized title and subtitle for 404 errors.
error.vue Refactored error page logic to use new error components. Added computed property to detect 404 errors and conditionally render not-found or general error layouts.
i18n/locales/de-DE/error.json, i18n/locales/en-GB/error.json Added localized button label for returning to the homepage in error scenarios.
docs/how-to/error-handling.md Added documentation explaining usage and customization of the new error layout component, with code examples.
docs/.vitepress/config.ts Updated documentation sidebar to include a new "Error Handling" entry under "How-Tos".

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant App
    participant ErrorLayout
    participant ErrorNotFound

    User->>App: Navigates to a page
    App->>App: Detects error (e.g., 404)
    alt Error is 404
        App->>ErrorNotFound: Render not found error
        ErrorNotFound->>ErrorLayout: Use error layout with 404 slots
    else Other error
        App->>ErrorLayout: Render error layout with title/subtitle slots
    end
    ErrorLayout-->>User: Displays error page with localized content
Loading

Poem

In the warren of code, a new path is found,
With layouts for errors and not-found abound.
Slots for your message, your button, your style,
With docs and translations that make rabbits smile.
Now when things go awry, hop home with a click—
Error handling’s never been quite this slick! 🐇✨


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@jkniest
Copy link
Member

jkniest commented May 20, 2025

I think it is more relevant for QA, but on the review app the 404 page doesn't work: https://pr-148-basecom-pond.fly.dev/asddasd

I just get an empty page and an error in the console:

Hydration completed but contains mismatches.

@jkniest
Copy link
Member

jkniest commented May 20, 2025

@coderabbitai review

Copy link

coderabbitai bot commented May 20, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

♻️ Duplicate comments (1)
i18n/locales/en-GB/error.json (1)

7-9: Duplicate translation verification

Refer to the comment on i18n/locales/de-DE/error.json to ensure the generalButton key is present and used consistently across all locales.

🧹 Nitpick comments (3)
docs/how-to/error-handling.md (1)

4-4: Naming inconsistency between documentation and component usage.

The documentation refers to the component as ErrorLayout, but in the usage example (line 22), it's referenced as LayoutError. This inconsistency could confuse developers implementing error pages.

Either update the documentation to consistently use LayoutError or update the example to use ErrorLayout, depending on the actual component name in the codebase.

error.vue (1)

42-49: Consider adding a fallback for missing error information.

The current implementation may display incomplete information if error.message or error.statusCode is undefined.

Consider adding fallbacks for these values:

<template #title>
-    {{ error?.message }}
+    {{ error?.message || $t('error.generalErrorMessage') }}
</template>
<template #subTitle>
-    {{ error?.statusCode }}
+    {{ error?.statusCode || $t('error.unknownStatusCode') }}
</template>

Don't forget to add the corresponding translation keys.

components/error/ErrorLayoutInner.vue (1)

13-15: Consider adding aria-label for better accessibility.

The button lacks an explicit accessible label which could improve screen reader experience.

<NuxtLinkLocale to="/">
-    <UiButton variant="link">{{ $t('error.generalButton') }}</UiButton>
+    <UiButton variant="link" :aria-label="$t('error.generalButtonAriaLabel')">{{ $t('error.generalButton') }}</UiButton>
</NuxtLinkLocale>

Don't forget to add the corresponding translation key.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between dd9d47d and 02f3370.

📒 Files selected for processing (9)
  • components/error/ErrorLayout.vue (1 hunks)
  • components/error/ErrorLayoutInner.vue (1 hunks)
  • components/error/ErrorNotFound.vue (1 hunks)
  • components/error/ErrorNotFoundInner.vue (1 hunks)
  • docs/.vitepress/config.ts (1 hunks)
  • docs/how-to/error-handling.md (1 hunks)
  • error.vue (2 hunks)
  • i18n/locales/de-DE/error.json (1 hunks)
  • i18n/locales/en-GB/error.json (1 hunks)
🔇 Additional comments (9)
i18n/locales/de-DE/error.json (1)

7-9:

✅ Verification successful

Verify translation key consistency

The new generalButton key under the error object matches the default button label in your error layout components. Ensure that the component looks up error.generalButton and that this key is present in all locale files to avoid missing translations at runtime.


🏁 Script executed:

#!/bin/bash
# Verify that all locale JSONs include the `generalButton` key
rg '"generalButton"' -l i18n/locales

Length of output: 98


🏁 Script executed:

#!/bin/bash
echo "Locale directories:"
ls -1 i18n/locales | sed -e 's/^/ - /'

echo ""
echo "generalButton presence in error.json:"
for f in i18n/locales/*/error.json; do
  locale=$(basename "$(dirname "$f")")
  if command -v jq &> /dev/null; then
    has=$(jq 'has("generalButton")' "$f")
  else
    has=$(grep -q '"generalButton"' "$f" && echo true || echo false)
  fi
  echo " - $locale: $has"
done

Length of output: 709


🏁 Script executed:

#!/bin/bash
echo "Inspecting structure of error.json for each locale:"
for f in i18n/locales/*/error.json; do
  locale=$(basename "$(dirname "$f")")
  echo ""
  echo "----- $locale -----"
  # Show the first 20 lines to understand nesting
  head -n 20 "$f"
done

Length of output: 1562


Translation key consistency verified

Both locale files define error.generalButton, so translations are in sync:

  • i18n/locales/de-DE/error.json – contains "generalButton": "Zurück zur Startseite"
  • i18n/locales/en-GB/error.json – contains "generalButton": "Back to homepage"

No missing keys detected.

docs/.vitepress/config.ts (1)

33-35:

✅ Verification successful

Confirm documentation path

You've added a sidebar link for "Error Handling" pointing to /how-to/error-handling. Make sure the target file exists and the path matches exactly.


🏁 Script executed:

#!/bin/bash
# Check for the new docs file
fd 'docs/how-to/error-handling.md'

Length of output: 34


🏁 Script executed:

#!/bin/bash
# Search for any markdown files related to "error handling" in the docs directory
fd 'error[-_]handling' docs -e md

Length of output: 65


Confirmed documentation path

The file docs/how-to/error-handling.md exists, so the sidebar link /how-to/error-handling is correct. No further changes needed.

docs/how-to/error-handling.md (1)

22-35: Example code structure appears correct.

The usage example correctly demonstrates how to customize the error layout component with named slots for title, subtitle, and button content.

components/error/ErrorNotFoundInner.vue (2)

1-10: Consistent implementation of error page using named slots.

The implementation correctly uses the component referenced in the documentation with appropriate named slots (title and subTitle) and localized content.


4-4:

✅ Verification successful

Verify that the translation key exists.

Make sure the translation key error.404.heading exists in all language files to avoid displaying raw translation keys to users.


🏁 Script executed:

#!/bin/bash
# Check if the translation key exists in language files
echo "Checking for required translation keys in language files..."
fd --extension json --exec grep -l "404.heading" {} \; | sort

Length of output: 193


🏁 Script executed:

#!/bin/bash
echo "Verifying nested translation key error.404.heading across all JSON locale files..."
for file in $(fd --extension json); do
  if jq -e '.error["404"].heading' "$file" >/dev/null 2>&1; then
    echo "$file"
  fi
done | sort

Length of output: 1460


🏁 Script executed:

#!/bin/bash
echo "Verifying presence of error.404.heading in each locale's error.json"
find i18n/locales -mindepth 1 -maxdepth 1 -type d | sort | while read dir; do
  locale=$(basename "$dir")
  file="$dir/error.json"
  if [ ! -f "$file" ]; then
    echo "$locale: error.json missing"
  else
    if jq -e '.error["404"].heading' "$file" >/dev/null 2>&1; then
      echo "$locale: ✅ present"
    else
      echo "$locale: ❌ missing 404.heading"
    fi
  fi
done

Length of output: 709


error.404.heading Translation Key Verified
The error.404.heading key is present in all locale files:

  • i18n/locales/de-DE/error.json
  • i18n/locales/en-GB/error.json

No further action required.

error.vue (1)

30-30: Good use of computed property for conditional rendering.

Using a computed property for the 404 check improves readability and maintainability.

components/error/ErrorLayoutInner.vue (3)

1-21: Well-structured error layout with appropriate slots.

The component provides a flexible structure with named slots that align with the documentation. The default implementations and fallbacks are appropriate.


6-6:

✅ Verification successful

Verify that the translation key exists.

Make sure the translation key error.generalHeadline exists in all language files to avoid displaying raw translation keys to users.


🏁 Script executed:

#!/bin/bash
# Check if the translation key exists in language files
echo "Checking for required translation keys in language files..."
fd --extension json --exec grep -l "generalHeadline" {} \; | sort

Length of output: 261


Verified translation key presence

The error.generalHeadline key is present in all locale files under i18n/locales:

  • i18n/locales/de-DE/error.json
  • i18n/locales/en-GB/error.json

No missing translations detected.


14-14:

✅ Verification successful

Verify that the translation key exists.

Make sure the translation key error.generalButton exists in all language files to avoid displaying raw translation keys to users.


🏁 Script executed:

#!/bin/bash
# Check if the translation key exists in language files
echo "Checking for required translation keys in language files..."
fd --extension json --exec grep -l "generalButton" {} \; | sort

Length of output: 259


🏁 Script executed:

#!/bin/bash
echo "Verifying presence of \"generalButton\" in all locale error.json files..."
exit_code=0

for locale_dir in $(find i18n/locales -mindepth 1 -maxdepth 1 -type d); do
  locale=$(basename "$locale_dir")
  file="$locale_dir/error.json"

  if [[ ! -f "$file" ]]; then
    echo "  ✗ error.json missing for locale: $locale"
    exit_code=1
  else
    if grep -q '"generalButton"' "$file"; then
      echo "$locale: key found"
    else
      echo "$locale: missing key \"generalButton\""
      exit_code=1
    fi
  fi
done

exit $exit_code

Length of output: 844


✅ Translation key verified across all locales

The error.generalButton key is present in:

  • i18n/locales/de-DE/error.json
  • i18n/locales/en-GB/error.json

No missing keys detected—no further action required.

@chlongng
Copy link
Author

@jkniest sorry, the 404 page should be working now. there was incorrect reference that i didnt catch when i was refactoring the filenames

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants