Skip to content

Fix: 404 Error Handler Crash - #171

Open
nikhil1205-ai wants to merge 1 commit into
c2siorg:mainfrom
nikhil1205-ai:fix/Error-handler-crash
Open

Fix: 404 Error Handler Crash#171
nikhil1205-ai wants to merge 1 commit into
c2siorg:mainfrom
nikhil1205-ai:fix/Error-handler-crash

Conversation

@nikhil1205-ai

Copy link
Copy Markdown

Description

This PR fixes the crash in the error handling system by removing the dependency on g.news_controller and introduces a generic error handler that captures all exceptions and renders a user-friendly HTML error page.

Related Issue

Fixes: #170

Motivation and Context

Previously, the 404 error handler relied on g.news_controller, which may not be initialized when a request hits an invalid route. This caused runtime errors and application crashes.

Additionally, error handling was limited and inconsistent across different types of failures.

This change introduces a centralized error handling mechanism that:

  • Handles all exceptions (404, 500, etc.)
  • Avoids reliance on request-scoped objects like g
  • Improves user experience by rendering a clean error page

How Has This Been Tested?

Ran the Flask application locally:

flask --app app.py run

Tested invalid route:

http://127.0.0.1:5000/invalid-route
Verified:
No crash occurs

  • Error page (error.html) is rendered
  • Correct status code is returned (e.g., 404)

Tested runtime error scenarios:

  • Simulated internal errors
  • Confirmed 500 error page is displayed

Environment:

  • OS: Windows 10
  • Browser: Chrome (latest version)

Screenshots (if appropriate):

Screenshot 2026-03-28 142118 Screenshot 2026-03-28 142328

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

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.

[BUG]: 404 handler crashes due to undefined g.news_controller

1 participant