Skip to content

Commit

Permalink
error pages
Browse files Browse the repository at this point in the history
  • Loading branch information
michelson committed Aug 11, 2023
1 parent 4638b69 commit 62c5132
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 227 deletions.
29 changes: 10 additions & 19 deletions app/controllers/errors_controller.rb
Original file line number Diff line number Diff line change
@@ -1,26 +1,17 @@
class ErrorsController < ApplicationController
layout "error"
layout "errors"

def show
@exception = request.env["action_dispatch.exception"]
@status_code = @exception.try(:status_code) ||
ActionDispatch::ExceptionWrapper.new(
request.env, @exception
).status_code

render view_for_code(@status_code), status: @status_code
def not_found
render "404"
end

private
def view_for_code(code)
supported_error_codes.fetch(code, "404")
end
def fatal
render "500"
end

def not_allowed
render "422"
end

def supported_error_codes
{
403 => "403",
404 => "404",
500 => "500"
}
end
end
2 changes: 1 addition & 1 deletion app/views/errors/404.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<p class="text-4xl font-bold tracking-tight text-brand-600 sm:text-5xl">404</p>
<div class="sm:ml-6">
<div class="sm:border-l sm:border-gray-200 sm:pl-6">
<h1 class="text-4xl font-bold tracking-tight text-gray-900 dark:text-gray-100 sm:text-5xl">
<h1 class="text-4xl font-bold tracking-tight text-gray-700 dark:text-gray-100 sm:text-5xl">
<%= gettext("Page not found") %>
</h1>
<p class="mt-1 text-base text-gray-500 dark:text-gray-300">
Expand Down
32 changes: 32 additions & 0 deletions app/views/errors/422.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

<div class="min-h-full bg-black px-4 py-16 sm:px-6 sm:py-24 md:grid md:place-items-center lg:px-8">
<div class="mx-auto max-w-max">
<main class="sm:flex">
<p class="text-4xl font-bold tracking-tight text-brand-600 sm:text-5xl">500</p>
<div class="sm:ml-6">
<div class="sm:border-l sm:border-gray-200 sm:pl-6">
<h1 class="text-4xl font-bold tracking-tight text-gray-700 dark:text-gray-100 sm:text-5xl">
<%= gettext("Access denied") %>
</h1>
<p class="mt-1 text-base text-gray-500 dark:text-gray-300">
<%= gettext("Please check the URL in the address bar and try again.") %>
</p>
</div>
<div class="mt-10 flex space-x-3 sm:border-l sm:border-transparent sm:pl-6">
<a
href="/"
class="inline-flex items-center rounded-md border border-transparent bg-brand-600 px-4 py-2 text-sm font-medium text-white shadow-sm hover:bg-brand-700 focus:outline-none focus:ring-2 focus:ring-brand-500 focus:ring-offset-2"
>
<%= gettext("Go back home") %>
</a>
<a
href="#"
class="inline-flex items-center rounded-md border border-transparent bg-brand-100 px-4 py-2 text-sm font-medium text-brand-700 hover:bg-brand-200 focus:outline-none focus:ring-2 focus:ring-brand-500 focus:ring-offset-2"
>
<%= gettext("Contact support") %>
</a>
</div>
</div>
</main>
</div>
</div>
2 changes: 1 addition & 1 deletion app/views/errors/500.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<p class="text-4xl font-bold tracking-tight text-brand-600 sm:text-5xl">500</p>
<div class="sm:ml-6">
<div class="sm:border-l sm:border-gray-200 sm:pl-6">
<h1 class="text-4xl font-bold tracking-tight text-gray-900 dark:text-gray-100 sm:text-5xl">
<h1 class="text-4xl font-bold tracking-tight text-gray-700 dark:text-gray-100 sm:text-5xl">
<%= gettext("Something went wrong") %>
</h1>
<p class="mt-1 text-base text-gray-500 dark:text-gray-300">
Expand Down
4 changes: 2 additions & 2 deletions app/views/layouts/errors.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<%# app/views/layouts/error.html.erb %>

<!DOCTYPE html>
<html>
<html class="dark">
<head>
<title>RauversionRor</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
Expand All @@ -12,7 +12,7 @@
<%= javascript_include_tag "application", "data-turbo-track": "reload", defer: true %>
</head>

<body>
<body class="dark:bg-black">
<main>
<%= yield %>
</main>
Expand Down
5 changes: 2 additions & 3 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 7.0

#config.exceptions_app = ->(env) {
# ErrorsController.action(:show).call(env)
#}
config.exceptions_app = self.routes


config.hosts << "chaskiq.sa.ngrok.io"
config.hosts << ENV['HOST']
Expand Down
2 changes: 1 addition & 1 deletion config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false

config.consider_all_requests_local = false
# config.consider_all_requests_local = false

# Do not eager load code on boot.
config.eager_load = false
Expand Down
3 changes: 3 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
get "/embed/sets/:playlist_id", to: "embeds#show_playlist"
get "/embed/sets/:playlist_id/private", to: "embeds#private_playlist"

get "/404" => "errors#not_found"
get "/500" => "errors#fatal"


resource :player, controller: "player"

Expand Down
67 changes: 0 additions & 67 deletions public/404.html

This file was deleted.

67 changes: 0 additions & 67 deletions public/422.html

This file was deleted.

66 changes: 0 additions & 66 deletions public/500.html

This file was deleted.

0 comments on commit 62c5132

Please sign in to comment.