moromi-error 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/ruby.yml +23 -0
- data/.gitignore +1 -0
- data/README.md +3 -5
- data/app/views/moromi/error/_default.html.slim +11 -0
- data/app/views/moromi/error/_default.json.jb +9 -0
- data/app/views/moromi/error/_default.json.jbuilder +3 -1
- data/config/locales/moromi-error.yml +14 -12
- data/lib/generators/moromi/error/views_generator.rb +10 -2
- data/lib/moromi/error.rb +11 -2
- data/lib/moromi/error/config.rb +3 -1
- data/lib/moromi/error/default_information_builder.rb +41 -0
- data/lib/moromi/error/default_logger.rb +60 -5
- data/lib/moromi/error/errors.rb +55 -22
- data/lib/moromi/error/information_buildable.rb +13 -0
- data/lib/moromi/error/renderer.rb +15 -2
- data/lib/moromi/error/rescue.rb +8 -4
- data/lib/moromi/error/version.rb +1 -1
- data/moromi-error.gemspec +6 -6
- metadata +33 -24
- data/app/views/moromi/error/_force_update.html.erb +0 -36
- data/app/views/moromi/error/_force_update.html.slim +0 -25
- data/app/views/moromi/error/_force_update.json.jbuilder +0 -6
- data/circle.yml +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 832c6cfe1cf0f2b4b4bf3986da115b1131a81fd3beedec14d282c0f29dfe8540
|
4
|
+
data.tar.gz: 0e1ced5d0279108a6e504087b836ee1591914eee2d812091a4e192fb83d00256
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 876be6091b110ac574c7e8757ce37f8da74d73419b07bd1e292511cea14bbc42cc4971299382b0dee9f611e9b01eca5fe08210f9f1a2153ad8fca2f64cb19130
|
7
|
+
data.tar.gz: f465b512ed31e6fa28a3714a1f21cf8c1ccacbf5e6202fb837c3382fc75460d5035fe3228e04348aff582e204eb658eb3cf72349769c6411864cb7e53d21a429
|
@@ -0,0 +1,23 @@
|
|
1
|
+
name: Ruby
|
2
|
+
|
3
|
+
on: [push, pull_request]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
test:
|
7
|
+
strategy:
|
8
|
+
fail-fast: false
|
9
|
+
matrix:
|
10
|
+
os: [ubuntu-latest]
|
11
|
+
ruby: [2.7, 3.0]
|
12
|
+
runs-on: ${{ matrix.os }}
|
13
|
+
steps:
|
14
|
+
- uses: actions/checkout@v2
|
15
|
+
- uses: ruby/setup-ruby@v1
|
16
|
+
with:
|
17
|
+
ruby-version: ${{ matrix.ruby }}
|
18
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
19
|
+
- run: |
|
20
|
+
gem install bundler
|
21
|
+
bundle config path vendor/bundle
|
22
|
+
bundle install --jobs 4 --retry 3
|
23
|
+
bundle exec rspec
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
# Moromi::Error
|
2
2
|
|
3
3
|
[![Latest Version](https://img.shields.io/gem/v/moromi-error.svg)](http://rubygems.org/gems/moromi-error)
|
4
|
-
[![
|
5
|
-
|
4
|
+
[![Build Status](https://github.com/moromi/moromi-error/workflows/Ruby/badge.svg)](https://github.com/moromi/moromi-error/actions)
|
6
5
|
Error templates.
|
7
6
|
|
8
7
|
## Installation
|
@@ -30,7 +29,6 @@ Or install it yourself as:
|
|
30
29
|
```ruby
|
31
30
|
Moromi::Error.configure do |config|
|
32
31
|
config.debug = true
|
33
|
-
config.store_url = 'https://itunes.apple.com/jp/app/idxxxxxxxxxx'
|
34
32
|
end
|
35
33
|
```
|
36
34
|
|
@@ -55,13 +53,13 @@ it's optional module.
|
|
55
53
|
|
56
54
|
### Copy Template
|
57
55
|
|
58
|
-
- jbuilder and erb
|
56
|
+
- jb and jbuilder and erb
|
59
57
|
|
60
58
|
```ruby
|
61
59
|
bundle exec rails g moromi:error:views -e erb
|
62
60
|
```
|
63
61
|
|
64
|
-
- jbuilder and slim
|
62
|
+
- jb and jbuilder and slim
|
65
63
|
|
66
64
|
```ruby
|
67
65
|
bundle exec rails g moromi:error:views -e slim
|
@@ -8,6 +8,8 @@ html lang="ja"
|
|
8
8
|
body
|
9
9
|
div
|
10
10
|
h1= "#{status} #{title}"
|
11
|
+
p= "RequestId: #{request.uuid}"
|
12
|
+
p= exception.error_title
|
11
13
|
|
12
14
|
- unless Rails.env.production?
|
13
15
|
table
|
@@ -18,8 +20,17 @@ html lang="ja"
|
|
18
20
|
tr
|
19
21
|
td debug_message
|
20
22
|
td= exception.debug_message
|
23
|
+
tr
|
24
|
+
td detail_url
|
25
|
+
td= exception.detail_url
|
21
26
|
|
22
27
|
- exception.errors.each do |error|
|
23
28
|
tr
|
24
29
|
td error
|
25
30
|
td= error
|
31
|
+
|
32
|
+
tr
|
33
|
+
td backtrace
|
34
|
+
td
|
35
|
+
- backtrace = exception.backtrace.presence || exception.original_exception&.backtrace || []
|
36
|
+
pre= safe_join(::Rails.backtrace_cleaner.clean(backtrace), '<br />'.html_safe)
|
@@ -1,18 +1,20 @@
|
|
1
1
|
en:
|
2
2
|
strings:
|
3
3
|
moromi-error:
|
4
|
-
an_error_has_occurred: 'An error has occurred.'
|
5
|
-
validation_error: 'Validation error.'
|
6
|
-
not_found: 'Not found.'
|
7
|
-
permission_denied: 'Permission denied.'
|
8
|
-
authentication_failed: 'Authentication failed.'
|
9
|
-
need_force_update: 'Need update.'
|
4
|
+
an_error_has_occurred: 'An error has occurred. error_code = %{error_code}'
|
5
|
+
validation_error: 'Validation error. error_code = %{error_code}'
|
6
|
+
not_found: 'Not found. error_code = %{error_code}'
|
7
|
+
permission_denied: 'Permission denied. error_code = %{error_code}'
|
8
|
+
authentication_failed: 'Authentication failed. error_code = %{error_code}'
|
9
|
+
need_force_update: 'Need update. error_code = %{error_code}'
|
10
|
+
too_many_requests: 'Too Many Requests. error_code = %{error_code}'
|
10
11
|
ja:
|
11
12
|
strings:
|
12
13
|
moromi-error:
|
13
|
-
an_error_has_occurred: 'エラーが発生しました。'
|
14
|
-
validation_error: '不正な入力です。'
|
15
|
-
not_found: '見つかりませんでした。'
|
16
|
-
permission_denied: '権限がありません。'
|
17
|
-
authentication_failed: '認証に失敗しました。'
|
18
|
-
need_force_update: '新しいバージョンのアプリがあります。'
|
14
|
+
an_error_has_occurred: 'エラーが発生しました。 error_code = %{error_code}'
|
15
|
+
validation_error: '不正な入力です。 error_code = %{error_code}'
|
16
|
+
not_found: '見つかりませんでした。 error_code = %{error_code}'
|
17
|
+
permission_denied: '権限がありません。 error_code = %{error_code}'
|
18
|
+
authentication_failed: '認証に失敗しました。 error_code = %{error_code}'
|
19
|
+
need_force_update: '新しいバージョンのアプリがあります。 error_code = %{error_code}'
|
20
|
+
too_many_requests: '所定の期間内に送信されたリクエスト数が多すぎます。 error_code = %{error_code}'
|
@@ -16,7 +16,8 @@ rails g moromi:error:views [options]
|
|
16
16
|
desc ''
|
17
17
|
def copy_or_fetch #:nodoc:
|
18
18
|
copy_html_templates
|
19
|
-
|
19
|
+
copy_jbuilder_templates
|
20
|
+
copy_jb_templates
|
20
21
|
end
|
21
22
|
|
22
23
|
private
|
@@ -28,13 +29,20 @@ rails g moromi:error:views [options]
|
|
28
29
|
end
|
29
30
|
end
|
30
31
|
|
31
|
-
def
|
32
|
+
def copy_jbuilder_templates
|
32
33
|
filename_pattern = File.join self.class.source_root, "*.json.jbuilder"
|
33
34
|
Dir.glob(filename_pattern).map {|f| File.basename f}.each do |f|
|
34
35
|
copy_file f, "app/views/moromi/error/#{f}"
|
35
36
|
end
|
36
37
|
end
|
37
38
|
|
39
|
+
def copy_jb_templates
|
40
|
+
filename_pattern = File.join self.class.source_root, "*.json.jb"
|
41
|
+
Dir.glob(filename_pattern).map {|f| File.basename f}.each do |f|
|
42
|
+
copy_file f, "app/views/moromi/error/#{f}"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
38
46
|
def template_engine
|
39
47
|
options[:template_engine]&.to_s&.downcase || 'erb'
|
40
48
|
end
|
data/lib/moromi/error.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'moromi/error/config'
|
2
|
-
require 'moromi/error/loggerable'
|
3
2
|
require 'moromi/error/default_logger'
|
3
|
+
require 'moromi/error/default_information_builder'
|
4
4
|
require 'moromi/error/engine'
|
5
5
|
require 'moromi/error/errors'
|
6
6
|
require 'moromi/error/renderer'
|
@@ -16,10 +16,19 @@ module Moromi
|
|
16
16
|
@config
|
17
17
|
end
|
18
18
|
|
19
|
+
def self.default_severity_mappings
|
20
|
+
{
|
21
|
+
Moromi::Error::Default => Logger::Severity::DEBUG,
|
22
|
+
ActionController::RoutingError => Logger::Severity::WARN
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
19
26
|
configure do |config|
|
20
27
|
config.debug = false
|
21
28
|
config.logger = Moromi::Error::DefaultLogger.new
|
22
|
-
config.
|
29
|
+
config.severity_mappings = default_severity_mappings
|
30
|
+
config.information_builder_klass = Moromi::Error::DefaultInformationBuilder
|
31
|
+
config.use_exception_notifier = false
|
23
32
|
end
|
24
33
|
end
|
25
34
|
end
|
data/lib/moromi/error/config.rb
CHANGED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'moromi/error/information_buildable'
|
2
|
+
|
3
|
+
module Moromi
|
4
|
+
module Error
|
5
|
+
class DefaultInformationBuilder
|
6
|
+
include ::Moromi::Error::InformationBuildable
|
7
|
+
|
8
|
+
def initialize(controller)
|
9
|
+
@controller = controller
|
10
|
+
end
|
11
|
+
|
12
|
+
def build
|
13
|
+
{
|
14
|
+
user_id: fetch_user_id(controller),
|
15
|
+
url: fetch_url(controller),
|
16
|
+
user_agent: fetch_user_agent(controller)
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def fetch_user_id(controller)
|
23
|
+
controller.respond_to?(:current_user) ? controller.current_user&.id : 0
|
24
|
+
rescue
|
25
|
+
nil
|
26
|
+
end
|
27
|
+
|
28
|
+
def fetch_url(controller)
|
29
|
+
controller.request.try(:url)
|
30
|
+
rescue
|
31
|
+
nil
|
32
|
+
end
|
33
|
+
|
34
|
+
def fetch_user_agent(controller)
|
35
|
+
controller.request.try(:user_agent)
|
36
|
+
rescue
|
37
|
+
nil
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -1,15 +1,70 @@
|
|
1
|
+
require 'moromi/error/loggerable'
|
2
|
+
|
1
3
|
module Moromi
|
2
4
|
module Error
|
3
5
|
class DefaultLogger
|
4
|
-
include Loggerable
|
6
|
+
include ::Moromi::Error::Loggerable
|
7
|
+
|
8
|
+
UNKNOWN = 'unknown'.freeze
|
5
9
|
|
6
10
|
def write(controller, status, title, exception, options, locals)
|
7
|
-
|
11
|
+
Moromi::Error.config.severity_mappings.each do |klass, severity|
|
12
|
+
if exception.is_a? klass
|
13
|
+
message = ([exception.message] + ::Rails.backtrace_cleaner.clean(Array(exception.backtrace).compact)).join('\n')
|
14
|
+
Rails.logger.add severity, message
|
15
|
+
return
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
Rails.logger.add log_severity(exception), to_ltsv(controller, exception) unless skip?(exception)
|
20
|
+
notify_exception(controller, exception)
|
21
|
+
rescue => e
|
22
|
+
backtrace = ::Rails.backtrace_cleaner.clean(e.backtrace).join("\n").gsub("\n", '\n')
|
23
|
+
Rails.logger.error "[#{self.class}#write] #{e.inspect} #{backtrace}"
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def to_ltsv(controller, exception)
|
29
|
+
backtrace = (exception&.backtrace || []).compact
|
30
|
+
information_builder = Moromi::Error.config.information_builder_klass.new(controller)
|
31
|
+
|
32
|
+
messages = {
|
33
|
+
error_class: exception.class,
|
34
|
+
message: exception.message,
|
35
|
+
errors: fetch_errors(exception).compact.join("\n").gsub("\n", '\n'),
|
36
|
+
backtrace: ::Rails.backtrace_cleaner.clean(backtrace).join("\n").gsub("\n", '\n')
|
37
|
+
}
|
38
|
+
messages.merge!(information_builder.build)
|
39
|
+
|
40
|
+
messages.map { |k, v| "#{k}:#{v}" }.join("\t")
|
41
|
+
rescue
|
42
|
+
(exception&.backtrace || []).compact.join("\n").gsub("\n", '\n')
|
43
|
+
end
|
44
|
+
|
45
|
+
def notify_exception(controller, exception)
|
46
|
+
return unless defined? ExceptionNotifier
|
47
|
+
return unless Moromi::Error.config.use_exception_notifier
|
48
|
+
|
49
|
+
ExceptionNotifier.notify_exception(exception, env: controller.request.env, data: {method: controller.request.method, url: controller.request.url})
|
50
|
+
end
|
51
|
+
|
52
|
+
def skip?(exception)
|
53
|
+
return false unless exception.respond_to?(:skip_logging?)
|
54
|
+
|
55
|
+
exception.skip_logging?
|
56
|
+
end
|
57
|
+
|
58
|
+
def log_severity(exception)
|
59
|
+
return Logger::Severity::ERROR unless exception.respond_to?(:log_severity)
|
60
|
+
|
61
|
+
exception.log_severity
|
62
|
+
end
|
8
63
|
|
9
|
-
|
10
|
-
|
64
|
+
def fetch_errors(exception)
|
65
|
+
return [exception.inspect] unless exception.respond_to?(:errors)
|
11
66
|
|
12
|
-
|
67
|
+
exception.errors
|
13
68
|
end
|
14
69
|
end
|
15
70
|
end
|
data/lib/moromi/error/errors.rb
CHANGED
@@ -5,34 +5,66 @@ module Moromi::Error
|
|
5
5
|
DEFAULT_TITLE = 'moromi-error.an_error_has_occurred'
|
6
6
|
DEFAULT_ERRORS = ['moromi-error.an_error_has_occurred']
|
7
7
|
|
8
|
-
attr_reader :code
|
9
|
-
attr_reader :title
|
10
8
|
attr_reader :errors
|
9
|
+
attr_reader :debug_message
|
10
|
+
attr_reader :log_severity
|
11
|
+
attr_accessor :original_exception
|
12
|
+
attr_accessor :detail_url
|
11
13
|
|
12
14
|
# @param [Integer] code
|
13
|
-
# @param [String]
|
15
|
+
# @param [String] error_title
|
14
16
|
# @param [Array<String>] errors
|
15
17
|
# @param [String] message
|
16
18
|
# @param [String] debug_message
|
17
|
-
|
19
|
+
# @param [String] detail_url
|
20
|
+
# @param [Boolean] skip_logging
|
21
|
+
# @param [Integer] log_severity
|
22
|
+
def initialize(code: nil, error_title: nil, errors: self.class::DEFAULT_ERRORS, message: nil, debug_message: nil, detail_url: nil, skip_logging: false, log_severity: Logger::Severity::ERROR)
|
18
23
|
super(message)
|
19
|
-
@code = code
|
20
|
-
@
|
21
|
-
@errors =
|
24
|
+
@code = code
|
25
|
+
@error_title = error_title
|
26
|
+
@errors = errors
|
22
27
|
@debug_message = debug_message if Moromi::Error.config.debug
|
28
|
+
@detail_url = detail_url
|
29
|
+
@skip_logging = skip_logging
|
30
|
+
@log_severity = log_severity
|
31
|
+
end
|
32
|
+
|
33
|
+
# @param [Exception] exception
|
34
|
+
# @return [Moromi::Error::Default]
|
35
|
+
def self.make(exception)
|
36
|
+
return exception if exception.is_a? ::Moromi::Error::Default
|
37
|
+
|
38
|
+
new(debug_message: exception.try(:message) || '').tap do |e|
|
39
|
+
e.original_exception = exception
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def code
|
44
|
+
@code || self.class::DEFAULT_CODE
|
45
|
+
end
|
46
|
+
|
47
|
+
def errors
|
48
|
+
Array(@errors).map(&method(:translate))
|
49
|
+
end
|
50
|
+
|
51
|
+
def error_title
|
52
|
+
translate(@error_title || self.class::DEFAULT_TITLE)
|
23
53
|
end
|
24
54
|
|
25
55
|
# @return [String]
|
26
56
|
def debug_message
|
27
57
|
return '' unless Moromi::Error.config.debug
|
28
|
-
|
58
|
+
|
59
|
+
@debug_message || cleaned_backtrace.first || ''
|
29
60
|
end
|
30
61
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
62
|
+
def skip_logging?
|
63
|
+
@skip_logging
|
64
|
+
end
|
65
|
+
|
66
|
+
def cleaned_backtrace
|
67
|
+
::Rails.backtrace_cleaner.clean(backtrace || [])
|
36
68
|
end
|
37
69
|
|
38
70
|
private
|
@@ -40,7 +72,11 @@ module Moromi::Error
|
|
40
72
|
# @param [String] key
|
41
73
|
# @return [String]
|
42
74
|
def translate(key)
|
43
|
-
I18n.
|
75
|
+
I18n.t(key, scope: [:strings], default: key.to_s) % translate_params
|
76
|
+
end
|
77
|
+
|
78
|
+
def translate_params
|
79
|
+
{error_code: code}
|
44
80
|
end
|
45
81
|
end
|
46
82
|
|
@@ -51,13 +87,7 @@ module Moromi::Error
|
|
51
87
|
# @param [Exception] exception
|
52
88
|
# @return [Moromi::Error::Default]
|
53
89
|
def self.make(exception)
|
54
|
-
|
55
|
-
return new(debug_message: exception.try(:backtrace), message: exception.message, errors: [exception.message])
|
56
|
-
end
|
57
|
-
|
58
|
-
if defined?(WeakParameters::ValidationError) && exception.is_a?(WeakParameters::ValidationError)
|
59
|
-
return new(debug_message: exception.message, message: exception.message)
|
60
|
-
end
|
90
|
+
return new(debug_message: 'ActiveRecord::RecordInvalid', message: exception.message, errors: [exception.message]) if exception.is_a? ActiveRecord::RecordInvalid
|
61
91
|
|
62
92
|
super(exception)
|
63
93
|
end
|
@@ -81,7 +111,10 @@ module Moromi::Error
|
|
81
111
|
class NeedForceUpdate < Default
|
82
112
|
DEFAULT_CODE = 10004
|
83
113
|
DEFAULT_ERRORS = ['moromi-error.need_force_update']
|
114
|
+
end
|
84
115
|
|
85
|
-
|
116
|
+
class TooManyRequests < Default
|
117
|
+
DEFAULT_CODE = 10005
|
118
|
+
DEFAULT_ERRORS = ['moromi-error.too_many_requests']
|
86
119
|
end
|
87
120
|
end
|
@@ -5,7 +5,6 @@ module Moromi::Error
|
|
5
5
|
|
6
6
|
ERROR_TEMPLATES = {
|
7
7
|
default: 'moromi/error/default',
|
8
|
-
force_update: 'moromi/error/force_update'
|
9
8
|
}.freeze
|
10
9
|
|
11
10
|
included do
|
@@ -40,11 +39,23 @@ module Moromi::Error
|
|
40
39
|
render_error(410, 'Gone', exception, options: options, locals: locals)
|
41
40
|
end
|
42
41
|
|
42
|
+
def render_too_many_requests(exception: Moromi::Error::Default.new, options: nil, locals: {})
|
43
|
+
render_error(429, 'Too Many Requests', exception, options: options, locals: locals)
|
44
|
+
end
|
45
|
+
|
43
46
|
def render_force_update(exception: Moromi::Error::NeedForceUpdate.new, options: nil, locals: {})
|
44
|
-
options = options || {partial: ERROR_TEMPLATES[:
|
47
|
+
options = options || {partial: ERROR_TEMPLATES[:default], layout: false}
|
45
48
|
render_bad_request(exception: exception, options: options, locals: locals)
|
46
49
|
end
|
47
50
|
|
51
|
+
def render_internal_server_error(exception: Moromi::Error::Default.new, options: nil, locals: {})
|
52
|
+
render_error(500, 'Internal Server Error', exception, options: options, locals: locals)
|
53
|
+
end
|
54
|
+
|
55
|
+
def render_service_unavailable(exception: Moromi::Error::Default.new, options: nil, locals: {})
|
56
|
+
render_error(503, 'Service Unavailable', exception, options: options, locals: locals)
|
57
|
+
end
|
58
|
+
|
48
59
|
private
|
49
60
|
|
50
61
|
def render_error(status, title, exception, options: nil, locals: {})
|
@@ -64,6 +75,8 @@ module Moromi::Error
|
|
64
75
|
format.html &render_block
|
65
76
|
format.json &render_block
|
66
77
|
end
|
78
|
+
rescue ActionController::UnknownFormat
|
79
|
+
render status: 406, body: "Not Acceptable"
|
67
80
|
end
|
68
81
|
end
|
69
82
|
end
|
data/lib/moromi/error/rescue.rb
CHANGED
@@ -4,12 +4,16 @@ module Moromi
|
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
|
6
6
|
included do
|
7
|
-
|
7
|
+
# 5xx error
|
8
|
+
rescue_from Moromi::Error::Default, with: -> (e) { render_internal_server_error(exception: e) }
|
9
|
+
|
10
|
+
# 4xx error
|
8
11
|
rescue_from Moromi::Error::ValidationError, with: -> (e) { render_bad_request(exception: e) }
|
9
|
-
rescue_from Moromi::Error::NotFound, with: -> (e) { render_not_found(exception: e) }
|
10
|
-
rescue_from Moromi::Error::PermissionDenied, with: -> (e) { render_forbidden(exception: e) }
|
11
12
|
rescue_from Moromi::Error::AuthenticationFailed, with: -> (e) { render_unauthorized(exception: e) }
|
12
|
-
rescue_from Moromi::Error::
|
13
|
+
rescue_from Moromi::Error::PermissionDenied, with: -> (e) { render_forbidden(exception: e) }
|
14
|
+
rescue_from Moromi::Error::NotFound, with: -> (e) { render_not_found(exception: e) }
|
15
|
+
rescue_from Moromi::Error::TooManyRequests, with: -> (e) { render_too_many_requests(exception: e) }
|
16
|
+
rescue_from Moromi::Error::NeedForceUpdate, with: -> (e) { render_force_update(exception: e) }
|
13
17
|
end
|
14
18
|
end
|
15
19
|
end
|
data/lib/moromi/error/version.rb
CHANGED
data/moromi-error.gemspec
CHANGED
@@ -19,14 +19,14 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
|
-
spec.required_ruby_version = '>= 2.
|
22
|
+
spec.required_ruby_version = '>= 2.6'
|
23
23
|
|
24
|
-
spec.add_dependency 'rails', ['>= 4.2', '< 6']
|
25
|
-
spec.add_dependency 'jbuilder'
|
24
|
+
spec.add_dependency 'rails', ['>= 4.2', '< 6.2']
|
26
25
|
|
27
|
-
spec.add_development_dependency "
|
28
|
-
spec.add_development_dependency "
|
29
|
-
spec.add_development_dependency "
|
26
|
+
spec.add_development_dependency "jbuilder"
|
27
|
+
spec.add_development_dependency "bundler"
|
28
|
+
spec.add_development_dependency "rake"
|
29
|
+
spec.add_development_dependency "rspec"
|
30
30
|
spec.add_development_dependency "rspec-rails"
|
31
31
|
spec.add_development_dependency "sqlite3"
|
32
32
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: moromi-error
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Takahiro Ooishi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-02-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -19,7 +19,7 @@ dependencies:
|
|
19
19
|
version: '4.2'
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: '6'
|
22
|
+
version: '6.2'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -29,7 +29,7 @@ dependencies:
|
|
29
29
|
version: '4.2'
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '6'
|
32
|
+
version: '6.2'
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: jbuilder
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -37,7 +37,7 @@ dependencies:
|
|
37
37
|
- - ">="
|
38
38
|
- !ruby/object:Gem::Version
|
39
39
|
version: '0'
|
40
|
-
type: :
|
40
|
+
type: :development
|
41
41
|
prerelease: false
|
42
42
|
version_requirements: !ruby/object:Gem::Requirement
|
43
43
|
requirements:
|
@@ -48,44 +48,44 @@ dependencies:
|
|
48
48
|
name: bundler
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|
50
50
|
requirements:
|
51
|
-
- - "
|
51
|
+
- - ">="
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version: '
|
53
|
+
version: '0'
|
54
54
|
type: :development
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
57
|
requirements:
|
58
|
-
- - "
|
58
|
+
- - ">="
|
59
59
|
- !ruby/object:Gem::Version
|
60
|
-
version: '
|
60
|
+
version: '0'
|
61
61
|
- !ruby/object:Gem::Dependency
|
62
62
|
name: rake
|
63
63
|
requirement: !ruby/object:Gem::Requirement
|
64
64
|
requirements:
|
65
|
-
- - "
|
65
|
+
- - ">="
|
66
66
|
- !ruby/object:Gem::Version
|
67
|
-
version: '
|
67
|
+
version: '0'
|
68
68
|
type: :development
|
69
69
|
prerelease: false
|
70
70
|
version_requirements: !ruby/object:Gem::Requirement
|
71
71
|
requirements:
|
72
|
-
- - "
|
72
|
+
- - ">="
|
73
73
|
- !ruby/object:Gem::Version
|
74
|
-
version: '
|
74
|
+
version: '0'
|
75
75
|
- !ruby/object:Gem::Dependency
|
76
76
|
name: rspec
|
77
77
|
requirement: !ruby/object:Gem::Requirement
|
78
78
|
requirements:
|
79
|
-
- - "
|
79
|
+
- - ">="
|
80
80
|
- !ruby/object:Gem::Version
|
81
|
-
version: '
|
81
|
+
version: '0'
|
82
82
|
type: :development
|
83
83
|
prerelease: false
|
84
84
|
version_requirements: !ruby/object:Gem::Requirement
|
85
85
|
requirements:
|
86
|
-
- - "
|
86
|
+
- - ">="
|
87
87
|
- !ruby/object:Gem::Version
|
88
|
-
version: '
|
88
|
+
version: '0'
|
89
89
|
- !ruby/object:Gem::Dependency
|
90
90
|
name: rspec-rails
|
91
91
|
requirement: !ruby/object:Gem::Requirement
|
@@ -121,6 +121,7 @@ executables: []
|
|
121
121
|
extensions: []
|
122
122
|
extra_rdoc_files: []
|
123
123
|
files:
|
124
|
+
- ".github/workflows/ruby.yml"
|
124
125
|
- ".gitignore"
|
125
126
|
- ".rspec"
|
126
127
|
- Gemfile
|
@@ -129,24 +130,33 @@ files:
|
|
129
130
|
- Rakefile
|
130
131
|
- app/views/moromi/error/_default.html.erb
|
131
132
|
- app/views/moromi/error/_default.html.slim
|
133
|
+
- app/views/moromi/error/_default.json.jb
|
132
134
|
- app/views/moromi/error/_default.json.jbuilder
|
133
|
-
- app/views/moromi/error/_force_update.html.erb
|
134
|
-
- app/views/moromi/error/_force_update.html.slim
|
135
|
-
- app/views/moromi/error/_force_update.json.jbuilder
|
136
135
|
- bin/rails
|
137
|
-
- circle.yml
|
138
136
|
- config/locales/moromi-error.yml
|
139
137
|
- lib/generators/moromi/error/views_generator.rb
|
140
138
|
- lib/moromi/error.rb
|
141
139
|
- lib/moromi/error/config.rb
|
140
|
+
- lib/moromi/error/default_information_builder.rb
|
142
141
|
- lib/moromi/error/default_logger.rb
|
143
142
|
- lib/moromi/error/engine.rb
|
144
143
|
- lib/moromi/error/errors.rb
|
144
|
+
- lib/moromi/error/information_buildable.rb
|
145
145
|
- lib/moromi/error/loggerable.rb
|
146
146
|
- lib/moromi/error/renderer.rb
|
147
147
|
- lib/moromi/error/rescue.rb
|
148
148
|
- lib/moromi/error/version.rb
|
149
149
|
- moromi-error.gemspec
|
150
|
+
- vendor/bin/bundle
|
151
|
+
- vendor/bin/htmldiff
|
152
|
+
- vendor/bin/ldiff
|
153
|
+
- vendor/bin/nokogiri
|
154
|
+
- vendor/bin/rackup
|
155
|
+
- vendor/bin/rails
|
156
|
+
- vendor/bin/rake
|
157
|
+
- vendor/bin/rspec
|
158
|
+
- vendor/bin/sprockets
|
159
|
+
- vendor/bin/thor
|
150
160
|
homepage: https://github.com/moromi/moromi-error
|
151
161
|
licenses:
|
152
162
|
- MIT
|
@@ -159,15 +169,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
159
169
|
requirements:
|
160
170
|
- - ">="
|
161
171
|
- !ruby/object:Gem::Version
|
162
|
-
version: '2.
|
172
|
+
version: '2.6'
|
163
173
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
164
174
|
requirements:
|
165
175
|
- - ">="
|
166
176
|
- !ruby/object:Gem::Version
|
167
177
|
version: '0'
|
168
178
|
requirements: []
|
169
|
-
|
170
|
-
rubygems_version: 2.5.1
|
179
|
+
rubygems_version: 3.0.3
|
171
180
|
signing_key:
|
172
181
|
specification_version: 4
|
173
182
|
summary: Error templates
|
@@ -1,36 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<html lang="ja">
|
3
|
-
<head>
|
4
|
-
<meta charset="utf-8" />
|
5
|
-
<title>Need Force Update</title>
|
6
|
-
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport" />
|
7
|
-
<meta name="robots" content="noindex" />
|
8
|
-
</head>
|
9
|
-
<body>
|
10
|
-
<div>
|
11
|
-
<h1><%= status %> <%= title %></h1>
|
12
|
-
<% unless Rails.env.production? %>
|
13
|
-
<table>
|
14
|
-
<tbody>
|
15
|
-
<tr>
|
16
|
-
<td>code</td>
|
17
|
-
<td><%= exception.code %></td>
|
18
|
-
</tr>
|
19
|
-
|
20
|
-
<tr>
|
21
|
-
<td>debug_message</td>
|
22
|
-
<td><%= exception.debug_message %></td>
|
23
|
-
</tr>
|
24
|
-
|
25
|
-
<% exception.errors.each do |error| %>
|
26
|
-
<tr>
|
27
|
-
<td>error</td>
|
28
|
-
<td><%= error %></td>
|
29
|
-
</tr>
|
30
|
-
<% end %>
|
31
|
-
</tbody>
|
32
|
-
</table>
|
33
|
-
<% end %>
|
34
|
-
</div>
|
35
|
-
</body>
|
36
|
-
</html>
|
@@ -1,25 +0,0 @@
|
|
1
|
-
doctype html
|
2
|
-
html lang="ja"
|
3
|
-
head
|
4
|
-
meta charset="utf-8"
|
5
|
-
title Need Force Update
|
6
|
-
meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"
|
7
|
-
meta name="robots" content="noindex"
|
8
|
-
body
|
9
|
-
div
|
10
|
-
h1= "#{status} #{title}"
|
11
|
-
|
12
|
-
- unless Rails.env.production?
|
13
|
-
table
|
14
|
-
tbody
|
15
|
-
tr
|
16
|
-
td code
|
17
|
-
td= exception.code
|
18
|
-
tr
|
19
|
-
td debug_message
|
20
|
-
td= exception.debug_message
|
21
|
-
|
22
|
-
- exception.errors.each do |error|
|
23
|
-
tr
|
24
|
-
td error
|
25
|
-
td= error
|