Skip to content

Rambulanceを使って404/500/422ページを整備 #1702

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

Merged
merged 41 commits into from
Jun 23, 2025
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
a39bdf6
Rambulance の導入と初期設定を追加
nacchan99 Jun 10, 2025
a4ce6e1
ErrorsController を新規作成(404/500/422用)
nacchan99 Jun 10, 2025
548d72a
500 Internal Server Error ページを追加
nacchan99 Jun 10, 2025
7c19b40
422 Unprocessable Entity ページを追加
nacchan99 Jun 10, 2025
a456487
エラーページ共通のヘッダー部分をパーシャル化
nacchan99 Jun 10, 2025
44d493b
共通パーシャル追加(フィードバック案内・Twitterタイムライン)※500/422は未確認
nacchan99 Jun 10, 2025
677d005
500/422エラーページの表示も確認済みに変更
nacchan99 Jun 11, 2025
62ad7c3
エラーページ(404/500/422)のリクエストテストを追加
nacchan99 Jun 11, 2025
4b52ff7
ErrorsControllerの不要なコメントを削除
nacchan99 Jun 11, 2025
7e4737c
コメント位置を上に移動して統一
nacchan99 Jun 11, 2025
9dac37e
errors/headerをインライン化し、partialを削除
nacchan99 Jun 11, 2025
c0d871a
errors/feedback_noticeをインライン化し、partialを削除
nacchan99 Jun 12, 2025
092c3dd
共通文言の表示確認テストをrequestspecに追加
nacchan99 Jun 12, 2025
8e7f468
refactor: 404・500・422 エラーページのルーティングを一元化
nacchan99 Jun 16, 2025
0103961
refactor: ErrorsController を show アクションに集約し旧アクションを削除
nacchan99 Jun 16, 2025
21dbe7b
refactor: エラーページのshow.htmlを新規作成しfooter_links_and_timelineパーシャルをインライン化
nacchan99 Jun 16, 2025
ee6d1de
refactor:不要になった旧エラービューとfooterパーシャルを削除
nacchan99 Jun 16, 2025
4e8612b
refactor:重複したroutes.drawブロックを削除しエラールーティングを昇順(404→422→500)に変更
nacchan99 Jun 16, 2025
2222744
refactor:application.rbからexceptions_app設定を削除しproduction/test環境へ移行
nacchan99 Jun 16, 2025
22c107b
feat: 開発/テスト環境向けのエラー確認ルートを追加
nacchan99 Jun 16, 2025
285999d
ルーティングから重複したRambulance::Engineのマウントを削除
nacchan99 Jun 16, 2025
5d202b7
Rambulance用の例外テンプレート(404/422/500)を追加
nacchan99 Jun 17, 2025
d064907
エラー表示用 show テンプレートにヘルパー連携を追加
nacchan99 Jun 17, 2025
5a6566d
エラー表示をヘルパー化
nacchan99 Jun 17, 2025
ca186cb
ErrorsController関連ルートを削除し、Rambulanceによる例外ハンドリングに統一
nacchan99 Jun 17, 2025
50bd22e
開発テスト環境にのみRambulanceマウント追加
nacchan99 Jun 17, 2025
c50c127
refactor: エラーページのビュー構成を変更
nacchan99 Jun 18, 2025
4457879
chore: 不要になった古いエラービューを削除
nacchan99 Jun 18, 2025
f86b750
fix: errors/showパーシャルでの変数の受け渡しを修正
nacchan99 Jun 18, 2025
29c6cac
fix(config): Rambulanceの例外マッピングを修正
nacchan99 Jun 18, 2025
48b231e
fix(helper): 予期せぬエラー発生時のメッセージを修正
nacchan99 Jun 18, 2025
8cd758d
feat: 開発用のエラーページプレビュー機能を追加
nacchan99 Jun 18, 2025
52bc61d
エラー画面の案内文を更新し、報告依頼の文言を追加
nacchan99 Jun 18, 2025
619801e
refactor: 400・403エラービューを共通の構成に統一
nacchan99 Jun 19, 2025
4df3a8a
feat: エラーページのプレビュー機能を動的に改善
nacchan99 Jun 19, 2025
cc5dad9
test: エラーページのリクエストスペックを追加
nacchan99 Jun 19, 2025
561e698
fix: 422エラービューのファイル名をRambulanceの仕様に統一
nacchan99 Jun 23, 2025
37ed1c4
refactor: 自作プレビュー機能を削除し、Rambulanceのルートに統一
nacchan99 Jun 23, 2025
9b25662
test: エラーページ(404, 422, 500, 400)のリクエストスペックを追加
nacchan99 Jun 23, 2025
ac24ce1
style: テストコードのクォートをシングルクォートに統一
nacchan99 Jun 23, 2025
3736488
fix: Rambulance導入に伴う不要なルーティング設定を削除
nacchan99 Jun 23, 2025
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
15 changes: 15 additions & 0 deletions app/controllers/errors_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class ErrorsController < ApplicationController
layout 'application' # エラー画面にも通常のアプリと同じレイアウトを適用
Copy link
Contributor

@rakuda-san-desu rakuda-san-desu Jun 11, 2025

Choose a reason for hiding this comment

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

このコメントはカットして良さそうです👀

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ご指摘ありがとうございます!
こちらのコミットで対応済みです🙌 4b52ff7


def not_found
render status: 404 # このアクションでは app/views/errors/not_found.html.erb が使用されます
Copy link
Contributor

@rakuda-san-desu rakuda-san-desu Jun 11, 2025

Choose a reason for hiding this comment

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

他所も同様ですが、
該当する行の上にコメントを書くと、他の部分と統一されて良さそうです🛠️

    # このアクションでは app/views/errors/not_found.html.erb が使用されます
    render status: 404 

Copy link
Contributor Author

Choose a reason for hiding this comment

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

統一しました🛠
対応コミットはこちらです→ 7e4737c

end

def internal_server_error
render status: 500 # このアクションでは app/views/errors/internal_server_error.html.erb が使用されます
end

def unprocessable_entity
render status: 422 # このアクションでは app/views/errors/unprocessable_entity.html.erb が使用されます
end
end
7 changes: 7 additions & 0 deletions app/views/errors/_feedback_notice.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<p>
フィードバックなどあれば [email protected] にメールしていただくか、
<br>
もしくは
<a href="https://github.com/coderdojo-japan/coderdojo.jp/issues/" target="_blank" rel="noopener">GitHub Issue</a>
に書いていただけると嬉しいです (>人< )✨
</p>
20 changes: 20 additions & 0 deletions app/views/errors/_footer_links_and_timeline.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<section id="timeline" class="text-center grayscale-bg" style="padding-bottom: 100px;">
<br>
<h3 class="text-center">
<a href="https://twitter.com/search?vertical=default&q=dojocon%20OR%20coderdojo%20OR%20%E3%82%B3%E3%83%BC%E3%83%80%E3%83%BC%E9%81%93%E5%A0%B4%20lang%3Aja" target="_blank" rel="noopener">
🐣 最近の情報発信
</a>
</h3>
<br>
<div class="twitter-timeline-wrapper">
<a class="twitter-timeline" href="https://twitter.com/CoderDojoJapan?ref_src=twsrc%5Etfw"
data-lang="ja"
data-chrome="noheader nofooter noborders"
data-dnt="true"
data-width="500"
data-tweet-limit="5">
@CoderDojoJapan アカウントのタイムライン
</a>
</div>
<script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
</section>
6 changes: 6 additions & 0 deletions app/views/errors/_header.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<div id="top" class="title text-center">
<i class="cd cd-logo"></i>
<h1>CoderDojo Japan</h1>
<p>子どものためのプログラミング道場</p>
<br>
</div>
17 changes: 17 additions & 0 deletions app/views/errors/internal_server_error.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<% provide(:title, "予期しないエラーが発生しました 😵‍💫") %>
<% provide(:desc, "申し訳ありません。サーバーで問題が発生しています。") %>

<%= render 'errors/header' %>

<section class="introduction text-center list">
<h2>
予期しないエラーが発生しました 😵‍💫
</h2>
<p>
現在、問題を調査しています。しばらくしてからもう一度お試しください。
<br>
</p>
<%= render 'errors/feedback_notice' %>
</section>

<%= render 'errors/footer_links_and_timeline' %>
27 changes: 3 additions & 24 deletions app/views/errors/not_found.html.erb
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
<% provide(:title, "ページが見つかりませんでした... 🥺💦") %>
<% provide(:desc, "ページが削除された可能性があります 🤔💭") %>

<div id="top" class="title text-center">
<i class="cd cd-logo"></i>
<h1>CoderDojo Japan</h1>
<p>子どものためのプログラミング道場</p>
<br>
</div>
<%= render 'errors/header' %>

<section class="introduction text-center list">
<h2>
Expand All @@ -16,23 +11,7 @@
ページが削除された可能性があります 🤔💭
<br>
</p>
<p>
フィードバックなどあれば [email protected] にメールしていただくか、
<br>
もしくは
<a href="https://github.com/coderdojo-japan/coderdojo.jp/issues/">GitHub Issue</a>
に書いていただけると嬉しいです (>人< )✨
</p>
<%= render 'errors/feedback_notice' %>
</section>

<section id="timeline" class="text-center grayscale-bg" style="padding-bottom: 100px;">
<br>
<h3 class="text-center">
<a href="https://twitter.com/search?vertical=default&q=dojocon%20OR%20coderdojo%20OR%20%E3%82%B3%E3%83%BC%E3%83%80%E3%83%BC%E9%81%93%E5%A0%B4%20lang%3Aja" target="_blank" rel="noopener">🐣 最近の情報発信</a>
</h3>
<br>
<div class="twitter-timeline-wrapper">
<a class="twitter-timeline" href="https://twitter.com/CoderDojoJapan?ref_src=twsrc%5Etfw" data-lang="ja" data-chrome="noheader nofooter noborders" data-dnt="true" data-width="500" data-tweet-limit="5">@CoderDojoJapan アカウントのタイムライン</a>
</div>
<script async="" await="" src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
</section>
<%= render 'errors/footer_links_and_timeline' %>
Copy link
Member

@yasulab yasulab Jun 11, 2025

Choose a reason for hiding this comment

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

Error 専用の Partial にしては個々に分割しすぎな印象なので (個々に分けるメリットより個々に分けたことよる煩雑さが上回って僕がメンテするとき辛いので)、 共通化できる箇所のみを1つの Partial にまとめる ようにしていただけると助かります!(>人< )✨

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ご指摘ありがとうございます!

errors/headerfeedback_notice はインライン化し、 footer_links_and_timeline のみ partial として残しました。

対応コミット:

  • errors/header のインライン化 ➡︎ 9dac37e
  • errors/feedback_notice のインライン化 ➡︎ c0d871a

ご確認よろしくお願いします!

17 changes: 17 additions & 0 deletions app/views/errors/unprocessable_entity.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<% provide(:title, "リクエストが処理できませんでした… 😢") %>
<% provide(:desc, "入力内容に誤りがあるか、リクエストが正しく送信されなかった可能性があります。") %>

<%= render 'errors/header' %>

<section class="introduction text-center list">
<h2>
リクエストが処理できませんでした… 😢
</h2>
<p>
入力内容に誤りがあるか、リクエストが正しく送信されなかった可能性があります。
<br>
</p>
<%= render 'errors/feedback_notice' %>
</section>

<%= render 'errors/footer_links_and_timeline' %>
4 changes: 4 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 8.0

# Rambulance が提供するエラー用ルーティングを使うようにする
config.exceptions_app = self.routes


# Please, add to the `ignore` list any other `lib` subdirectories that do
# not contain `.rb` files, or that should not be reloaded or eager loaded.
# Common ones are `templates`, `generators`, or `middleware`, for example.
Expand Down
7 changes: 7 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,11 @@

# Check development sent emails
mount LetterOpenerWeb::Engine, at: "/letter_opener" if Rails.env.development?
mount Rambulance::Engine => "/"

if Rails.env.development? || Rails.env.test?
get "/trigger_500", to: ->(env) { raise "Triggering 500 error" }
get "/trigger_422", to: "errors#unprocessable_entity"
end

end
17 changes: 15 additions & 2 deletions spec/requests/errors_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,25 @@
include Rambulance::TestHelper

describe "Error requests" do
it 'should render a corresponding error page' do
it 'renders the 404 error page' do
with_exceptions_app do
get '/does_not_exist'
end
expect(response.status).to eq(404)
Copy link
Contributor

Choose a reason for hiding this comment

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

「子どものためのプログラミング道場」など、必ず表示されるテキストが存在するかも確認しておくと、さらに安心できそうです👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

テストを追加しました🙌
092c3dd
よろしくお願いします!

end

assert_equal 404, response.status
it 'renders the 422 error page' do
with_exceptions_app do
get '/trigger_422'
end
expect(response.status).to eq(422)
end

it 'renders the 500 error page' do
with_exceptions_app do
get '/trigger_500'
end
expect(response.status).to eq(500)
end
end
end