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

Custom error Pages for Dev #4006

Merged
merged 2 commits into from
Dec 4, 2024
Merged

Custom error Pages for Dev #4006

merged 2 commits into from
Dec 4, 2024

Conversation

BenjaminSsempala
Copy link
Contributor

@BenjaminSsempala BenjaminSsempala commented Dec 4, 2024

Description

Custom error pages for Nginx- Dev

Testing

  • Tested locally
  • Tested against staging environment
  • Relevant tests passed: [List test names]

Affected Services

  • Which services were modified:
    • nginx

Endpoints Ready for Testing

  • New endpoints ready for testing:
    • Endpoint 1
    • Endpoint 2
    • Other...

API Documentation Updated?

  • Yes, API documentation was updated
  • No, API documentation does not need updating

Additional Notes

[Add any additional notes or comments here]

Summary by CodeRabbit

  • New Features

    • Enhanced error handling with custom HTML pages for HTTP status codes 500, 404, 403, and 401.
    • Improved user experience with detailed messages and links back to the home page during error scenarios.
  • Bug Fixes

    • Replaced simple JSON error messages with structured HTML responses for better clarity and consistency.

Copy link
Contributor

coderabbitai bot commented Dec 4, 2024

📝 Walkthrough

Walkthrough

The changes involve updating the nginx-config ConfigMap in both the development and staging configurations for NGINX. The modifications primarily focus on enhancing error handling for HTTP status codes 500, 404, 403, and 401 by replacing previous error page directives with new custom locations. Each new location returns detailed HTML responses, improving user experience during error scenarios. The overall structure of the configuration is maintained, but the error handling capabilities are significantly enhanced with structured HTML content and styling.

Changes

File Path Change Summary
k8s/nginx/development/global-config.yaml Updated error page locations for 500, 404, 403, and 401 to custom locations; added new location blocks for custom error pages with structured HTML responses.
k8s/nginx/staging/global-config.yaml Similar updates as in development, replacing error page locations for 500, 404, 403, and 401 with custom locations and adding new location blocks for detailed HTML error responses.

Possibly related PRs

🎉 In the land of NGINX, where errors once roamed,
Custom pages now shine, making users feel at home.
With HTML styling, they greet every plight,
Turning frowns into smiles, making everything right!
So here's to the changes, both clever and bright,
A toast to the coders, who brought this to light! 🍾


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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 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.

Copy link

codecov bot commented Dec 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 11.73%. Comparing base (4718807) to head (7c482ef).
Report is 60 commits behind head on staging.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff            @@
##           staging    #4006   +/-   ##
========================================
  Coverage    11.73%   11.73%           
========================================
  Files          114      114           
  Lines        15330    15330           
  Branches       319      319           
========================================
  Hits          1799     1799           
  Misses       13531    13531           

Copy link
Contributor

@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: 1

🧹 Outside diff range and nitpick comments (3)
k8s/nginx/development/global-config.yaml (2)

21-147: Consider extracting common styles to reduce duplication

The HTML error pages share identical CSS styles with only color variations. Consider implementing these as separate CSS files and including them via nginx's sub_filter directive for better maintainability.

Example configuration:

+  # Add to the main nginx configuration
+  http {
+    sub_filter_once off;
+    sub_filter '__STYLE_URL__' '/static/error-pages.css';
+  }

Then modify the error pages to reference the external stylesheet:

-    <style>
-        * { margin: 0; padding: 0; box-sizing: border-box; }
-        ...
-    </style>
+    <link rel="stylesheet" href="__STYLE_URL__">
🧰 Tools
🪛 yamllint (1.35.1)

[error] 110-110: trailing spaces

(trailing-spaces)


[error] 137-137: trailing spaces

(trailing-spaces)


23-48: Enhance accessibility support

Consider adding the following accessibility improvements:

  • Add lang="en" attribute to HTML tags
  • Include ARIA labels for interactive elements
  • Add role="alert" to error messages

Example improvement for the 500 error page:

-      <html>
+      <html lang="en">
       <head>
           <title>500 - Internal Server Error</title>
       </head>
       <body>
           <div class="container">
-              <div class="error-code">500</div>
+              <div class="error-code" role="alert" aria-label="Error code 500">500</div>

Also applies to: 53-81, 84-111, 114-146

k8s/nginx/staging/global-config.yaml (1)

14-150: Consider using a template system for environment configurations

The error pages are identical between development and staging environments. Consider using a template system or including shared configurations to reduce duplication and maintenance overhead.

Example approach using environment variables:

# shared/error-pages.conf
error_page 500 = @custom_internal_server_error;
error_page 404 = @custom_page_not_found;
error_page 403 = @custom_access_denied;
error_page 401 = @custom_unauthorized;

# Then in each environment's config:
include shared/error-pages.conf;
🧰 Tools
🪛 yamllint (1.35.1)

[error] 113-113: trailing spaces

(trailing-spaces)


[error] 140-140: trailing spaces

(trailing-spaces)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 0439216 and 7c482ef.

📒 Files selected for processing (2)
  • k8s/nginx/development/global-config.yaml (1 hunks)
  • k8s/nginx/staging/global-config.yaml (1 hunks)
🧰 Additional context used
🪛 yamllint (1.35.1)
k8s/nginx/development/global-config.yaml

[error] 110-110: trailing spaces

(trailing-spaces)


[error] 137-137: trailing spaces

(trailing-spaces)

k8s/nginx/staging/global-config.yaml

[error] 113-113: trailing spaces

(trailing-spaces)


[error] 140-140: trailing spaces

(trailing-spaces)

🔇 Additional comments (1)
k8s/nginx/development/global-config.yaml (1)

11-14: Consider API clients when serving HTML error pages

While the HTML error pages enhance the user experience for browser clients, API clients expecting JSON responses might be affected. Consider adding content negotiation based on the Accept header.

Comment on lines +24 to +150
</html>';
}

location @custom_access_denied {
return 403 '
<!DOCTYPE html>
<html>
<head>
<title>403 - Access Denied</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, Helvetica, Arial, sans-serif; background: #f5f7fa; color: #2d3748; min-height: 100vh; display: flex; flex-direction: column; }
.container { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 2rem; text-align: center; }
.error-code { font-size: 8rem; font-weight: bold; color: #d69e2e; margin-bottom: 1rem; text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1); }
.title { font-size: 2rem; font-weight: 600; margin-bottom: 1rem; color: #2d3748; }
.message { font-size: 1.2rem; color: #4a5568; margin-bottom: 2rem; max-width: 600px; line-height: 1.6; }
.home-button { background-color: #d69e2e; color: white; padding: 0.75rem 1.5rem; border-radius: 0.375rem; text-decoration: none; font-weight: 500; transition: background-color 0.2s; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); }
.home-button:hover { background-color: #b7791f; }
</style>
</head>
<body>
<div class=\"container\">
<div class=\"error-code\">403</div>
<h1 class=\"title\">Access Denied</h1>
<p class=\"message\">
You don’t have permission to access this resource. If you believe this is a mistake, please contact the administrator.
</p>
<a href=\"/\" class=\"home-button\">Back to Home</a>
</div>
</body>
</html>';
}

location @custom_unauthorized {
return 401 '
<!DOCTYPE html>
<html>
<head>
<title>401 - Unauthorized</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, Helvetica, Arial, sans-serif; background: #f5f7fa; color: #2d3748; min-height: 100vh; display: flex; flex-direction: column; }
.container { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 2rem; text-align: center; }
.error-code { font-size: 8rem; font-weight: bold; color: #dd6b20; margin-bottom: 1rem; text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1); }
.title { font-size: 2rem; font-weight: 600; margin-bottom: 1rem; color: #2d3748; }
.message { font-size: 1.2rem; color: #4a5568; margin-bottom: 2rem; max-width: 600px; line-height: 1.6; }
.home-button { background-color: #dd6b20; color: white; padding: 0.75rem 1.5rem; border-radius: 0.375rem; text-decoration: none; font-weight: 500; transition: background-color 0.2s; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); }
.home-button:hover { background-color: #c05621; }
</style>
</head>
<body>
<div class=\"container\">
<div class=\"error-code\">401</div>
<h1 class=\"title\">Unauthorized</h1>
<p class=\"message\">
You need to log in to access this page. Please check your credentials and try again.
</p>
<a href=\"/\" class=\"home-button\">Back to Home</a>
</div>
</body>
</html>';
}

location @custom_page_not_found {
return 404 '
<!DOCTYPE html>
<html>
<head>
<title>404 - Page Not Found</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, Helvetica, Arial, sans-serif; background: #f5f7fa; color: #2d3748; min-height: 100vh; display: flex; flex-direction: column; }
.container { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 2rem; text-align: center; }
.error-code { font-size: 8rem; font-weight: bold; color: #4299e1; margin-bottom: 1rem; text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1); }
.title { font-size: 2rem; font-weight: 600; margin-bottom: 1rem; color: #2d3748; }
.message { font-size: 1.2rem; color: #4a5568; margin-bottom: 2rem; max-width: 600px; line-height: 1.6; }
.home-button { background-color: #4299e1; color: white; padding: 0.75rem 1.5rem; border-radius: 0.375rem; text-decoration: none; font-weight: 500; transition: background-color 0.2s; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); }
.home-button:hover { background-color: #3182ce; }
footer { text-align: center; padding: 1.5rem; background-color: white; color: #718096; box-shadow: 0 -2px 4px rgba(0, 0, 0, 0.05); }
.animation { margin-bottom: 2rem; font-size: 4rem; animation: bounce 2s infinite; }
@keyframes bounce { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-20px); } }
</style>
</head>
<body>
<div class=\"container\">
<div class=\"animation\">🤔</div>
<div class=\"error-code\">404</div>
<h1 class=\"title\">Page Not Found</h1>
<p class=\"message\">
Oops! The page you are looking for seems to have vanished into thin air.
Do not worry, you can navigate back to our home page or try searching for what you need.
</p>
<a href=\"/\" class=\"home-button\">Back to Home</a>
</div>
<footer>
© 2024 AirQo. All rights reserved.
</footer>
</body>
</html>';
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add security headers for HTML responses

Consider adding security headers for the HTML error pages to enhance security:

  • Content-Security-Policy
  • X-Content-Type-Options
  • X-Frame-Options

Example implementation:

     location @custom_internal_server_error {
+      add_header Content-Security-Policy "default-src 'self'; style-src 'unsafe-inline'";
+      add_header X-Content-Type-Options nosniff;
+      add_header X-Frame-Options DENY;
       return 500 '

Committable suggestion skipped: line range outside the PR's diff.

🧰 Tools
🪛 yamllint (1.35.1)

[error] 113-113: trailing spaces

(trailing-spaces)


[error] 140-140: trailing spaces

(trailing-spaces)

@Baalmart Baalmart merged commit f6ce34c into staging Dec 4, 2024
52 checks passed
@Baalmart Baalmart deleted the custom-errordev branch December 4, 2024 21:06
@Baalmart Baalmart mentioned this pull request Dec 4, 2024
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants