Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Engine-scoped error pages — 404 (`ActiveRecord::RecordNotFound`) and 500 (unhandled `StandardError` in production) now render within the dashboard chrome instead of falling through to the host app's error pages; in development `consider_all_requests_local` keeps the standard Rails debug page
- Covering indexes added to dummy app schema — `solid_queue_jobs (finished_at, created_at)` for the slow-job scan; `(queue_name, created_at)` on `solid_queue_scheduled_executions` and `solid_queue_blocked_executions` (both previously lacked a queue-name index)
- Install generator — `rails generate solid_stack_web:install` creates `config/initializers/solid_stack_web.rb` with every config option documented inline and injects the mount line into `config/routes.rb`
- `SolidStackWeb.mount_path` — returns the path at which the engine is mounted in the host app, derived automatically from routes; use `link_to "Dashboard", SolidStackWeb.mount_path` to link to the dashboard without hardcoding the path
Expand Down
1 change: 0 additions & 1 deletion ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ The path to v1.0.0 is staged: first achieve feature parity with `solid_queue_das
> _Make it easy to adopt and easy to contribute to._

### Remaining
- **Error pages** — engine-scoped 404/500 views so errors stay within the dashboard chrome
- **Changelog-driven upgrade notes** — `UPGRADING.md` for any breaking configuration changes

---
Expand Down
15 changes: 15 additions & 0 deletions app/controllers/solid_stack_web/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ class ApplicationController < ActionController::Base
before_action :authenticate!
around_action :with_database_connection

rescue_from StandardError do |exception|
raise exception if Rails.application.config.consider_all_requests_local
render_internal_server_error
end

rescue_from ActiveRecord::RecordNotFound, with: :render_not_found

helper_method :current_section

private
Expand Down Expand Up @@ -43,5 +50,13 @@ def authenticate!
def request_basic_auth
request_http_basic_authentication("Solid Stack Dashboard")
end

def render_not_found
render "solid_stack_web/errors/not_found", status: :not_found
end

def render_internal_server_error
render "solid_stack_web/errors/internal_server_error", status: :internal_server_error
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<div class="sqw-page-header">
<h1 class="sqw-page-title">Something Went Wrong</h1>
</div>

<div class="sqw-empty">
<p class="sqw-empty__title">500 &mdash; An unexpected error occurred.</p>
<p class="sqw-empty__hint"><%= link_to "Back to Dashboard", root_path, class: "sqw-btn sqw-btn--secondary" %></p>
</div>
8 changes: 8 additions & 0 deletions app/views/solid_stack_web/errors/not_found.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<div class="sqw-page-header">
<h1 class="sqw-page-title">Not Found</h1>
</div>

<div class="sqw-empty">
<p class="sqw-empty__title">404 &mdash; The record you&rsquo;re looking for doesn&rsquo;t exist or has been removed.</p>
<p class="sqw-empty__hint"><%= link_to "Back to Dashboard", root_path, class: "sqw-btn sqw-btn--secondary" %></p>
</div>
40 changes: 40 additions & 0 deletions spec/requests/solid_stack_web/errors_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
require "rails_helper"

RSpec.describe "Error pages", type: :request do
let(:engine_root) { "/solid_stack" }

describe "404 Not Found" do
it "renders the engine 404 page when a record is not found" do
get "#{engine_root}/jobs/99999999"
expect(response).to have_http_status(:not_found)
expect(response.body).to include("Not Found")
expect(response.body).to include("404")
end

it "renders within the dashboard chrome" do
get "#{engine_root}/jobs/99999999"
expect(response.body).to include("sqw-header")
expect(response.body).to include("Back to Dashboard")
end
end

describe "500 Internal Server Error" do
before do
allow(Rails.application.config).to receive(:consider_all_requests_local).and_return(false)
allow_any_instance_of(SolidStackWeb::JobsController).to receive(:index).and_raise(StandardError, "test error")
end

it "renders the engine 500 page on an unhandled error" do
get "#{engine_root}/jobs"
expect(response).to have_http_status(:internal_server_error)
expect(response.body).to include("Something Went Wrong")
expect(response.body).to include("500")
end

it "renders within the dashboard chrome" do
get "#{engine_root}/jobs"
expect(response.body).to include("sqw-header")
expect(response.body).to include("Back to Dashboard")
end
end
end