Skip to content

Commit 0103961

Browse files
committed
refactor: ErrorsController を show アクションに集約し旧アクションを削除
1 parent 8e7f468 commit 0103961

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

app/controllers/errors_controller.rb

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,28 @@
11
class ErrorsController < ApplicationController
2-
layout 'application'
2+
before_action :set_error_message
33

4-
def not_found
5-
# このアクションでは app/views/errors/not_found.html.erb が使用されます
6-
render status: 404
4+
def show
5+
render :show, status: @status_code
76
end
87

9-
def internal_server_error
10-
# このアクションでは app/views/errors/internal_server_error.html.erb が使用されます
11-
render status: 500
12-
end
8+
private
139

14-
def unprocessable_entity
15-
# このアクションでは app/views/errors/unprocessable_entity.html.erb が使用されます
16-
render status: 422
17-
end
10+
def set_error_message
11+
@status_code = params[:status_code].to_i
12+
13+
case @status_code
14+
when 404
15+
@title = "ページが見つかりませんでした... 🥺💦"
16+
@desc = "ページが削除された可能性があります 🤔💭"
17+
when 422
18+
@title = "リクエストが処理できませんでした… 😢"
19+
@desc = "入力内容に誤りがあるか、リクエストが正しく送信されなかった可能性があります。"
20+
when 500
21+
@title = "予期しないエラーが発生しました 😵‍💫"
22+
@desc = "申し訳ありません。サーバーで問題が発生しています。"
23+
else
24+
@title = "予期せぬエラーが発生しました…😵"
25+
@desc = "しばらく経ってから再度お試しください。"
26+
end
27+
end
1828
end

0 commit comments

Comments
 (0)