commit e7c779a3de3ffe6c35b37c5542971b0c2318b91a
parent 9ca3bafbdd25ba39d7689a97361704affcb498f1
Author: Ryan Jeffrey <ryan@ryanmj.xyz>
Date: Wed, 23 Feb 2022 21:47:56 -0800
Errors controller
Diffstat:
8 files changed, 34 insertions(+), 68 deletions(-)
diff --git a/app/controllers/errors_controller.rb b/app/controllers/errors_controller.rb
@@ -0,0 +1,17 @@
+class ErrorsController < ApplicationController
+def not_found
+ render status: 404
+ end
+
+ def internal_server
+ render status: 500
+ end
+
+ def unprocessable
+ render status: 422
+ end
+
+ def unacceptable
+ render status: 406
+ end
+end
diff --git a/app/helpers/errors_helper.rb b/app/helpers/errors_helper.rb
@@ -0,0 +1,2 @@
+module ErrorsHelper
+end
diff --git a/app/views/errors/not_found.html.erb b/app/views/errors/not_found.html.erb
@@ -0,0 +1,2 @@
+<h1>Errors#not_found</h1>
+<p>Find me in app/views/errors/not_found.html.erb</p>
diff --git a/config/application.rb b/config/application.rb
@@ -85,6 +85,8 @@ module Site
class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 7.0
+ # Handle errors myself.
+ config.exceptions_app = self.routes
config.public_file_server.enabled = true
diff --git a/config/routes.rb b/config/routes.rb
@@ -1,6 +1,10 @@
Rails.application.routes.draw do
root 'posts#index'
+ # Error routes
+ get '/404', to: 'errors#not_found'
+ get '/500', to: 'errors#internal_server'
+ get '/422', to: 'errors#unprocessable'
# Blog.
get '/posts', to: 'posts#blog_index'
get '/posts/:url', to: 'posts#show'
diff --git a/public/404.html b/public/404.html
@@ -1 +0,0 @@
-TEST TEST
diff --git a/public/422.html b/public/422.html
@@ -1,67 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
- <title>The change you wanted was rejected (422)</title>
- <meta name="viewport" content="width=device-width,initial-scale=1">
- <style>
- .rails-default-error-page {
- background-color: #EFEFEF;
- color: #2E2F30;
- text-align: center;
- font-family: arial, sans-serif;
- margin: 0;
- }
-
- .rails-default-error-page div.dialog {
- width: 95%;
- max-width: 33em;
- margin: 4em auto 0;
- }
-
- .rails-default-error-page div.dialog > div {
- border: 1px solid #CCC;
- border-right-color: #999;
- border-left-color: #999;
- border-bottom-color: #BBB;
- border-top: #B00100 solid 4px;
- border-top-left-radius: 9px;
- border-top-right-radius: 9px;
- background-color: white;
- padding: 7px 12% 0;
- box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
- }
-
- .rails-default-error-page h1 {
- font-size: 100%;
- color: #730E15;
- line-height: 1.5em;
- }
-
- .rails-default-error-page div.dialog > p {
- margin: 0 0 1em;
- padding: 1em;
- background-color: #F7F7F7;
- border: 1px solid #CCC;
- border-right-color: #999;
- border-left-color: #999;
- border-bottom-color: #999;
- border-bottom-left-radius: 4px;
- border-bottom-right-radius: 4px;
- border-top-color: #DADADA;
- color: #666;
- box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
- }
- </style>
-</head>
-
-<body class="rails-default-error-page">
- <!-- This file lives in public/422.html -->
- <div class="dialog">
- <div>
- <h1>The change you wanted was rejected.</h1>
- <p>Maybe you tried to change something you didn't have access to.</p>
- </div>
- <p>If you are the application owner check the logs for more information.</p>
- </div>
-</body>
-</html>
diff --git a/test/controllers/errors_controller_test.rb b/test/controllers/errors_controller_test.rb
@@ -0,0 +1,7 @@
+require "test_helper"
+
+class ErrorsControllerTest < ActionDispatch::IntegrationTest
+ # test "the truth" do
+ # assert true
+ # end
+end