moromi-error 0.2.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/release.yml +33 -0
  3. data/.github/workflows/ruby.yml +23 -0
  4. data/.gitignore +1 -0
  5. data/README.md +3 -5
  6. data/app/views/moromi/error/{_default.html.erb → default.html.erb} +0 -0
  7. data/app/views/moromi/error/{_default.html.slim → default.html.slim} +11 -0
  8. data/app/views/moromi/error/default.json.jb +9 -0
  9. data/app/views/moromi/error/{_force_update.json.jbuilder → default.json.jbuilder} +3 -2
  10. data/config/locales/moromi-error.yml +14 -12
  11. data/lib/generators/moromi/error/views_generator.rb +10 -2
  12. data/lib/moromi/error/config.rb +3 -1
  13. data/lib/moromi/error/default_information_builder.rb +41 -0
  14. data/lib/moromi/error/default_logger.rb +60 -5
  15. data/lib/moromi/error/errors.rb +55 -22
  16. data/lib/moromi/error/information_buildable.rb +13 -0
  17. data/lib/moromi/error/renderer.rb +20 -5
  18. data/lib/moromi/error/rescue.rb +8 -4
  19. data/lib/moromi/error/version.rb +1 -1
  20. data/lib/moromi/error.rb +11 -2
  21. data/moromi-error.gemspec +7 -6
  22. data/vendor/bin/bundle +114 -0
  23. data/vendor/bin/htmldiff +29 -0
  24. data/vendor/bin/ldiff +29 -0
  25. data/vendor/bin/nokogiri +29 -0
  26. data/vendor/bin/rackup +29 -0
  27. data/vendor/bin/rails +29 -0
  28. data/vendor/bin/rake +29 -0
  29. data/vendor/bin/rspec +29 -0
  30. data/vendor/bin/sprockets +29 -0
  31. data/vendor/bin/thor +29 -0
  32. metadata +51 -33
  33. data/app/views/moromi/error/_default.json.jbuilder +0 -5
  34. data/app/views/moromi/error/_force_update.html.erb +0 -36
  35. data/app/views/moromi/error/_force_update.html.slim +0 -25
  36. data/circle.yml +0 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 3b3488c51946c8ca81848716ba4a10bb6e04143f
4
- data.tar.gz: a134a2a13ba6306c7524ede717a153db476979da
2
+ SHA256:
3
+ metadata.gz: 5936263f9533c71c7ff02f65e8edc1e443969de98a74cbf87a49735d9877a77f
4
+ data.tar.gz: c4909ef90986ab0807fd01609ebd36566ce4ddd563a00b526f08262b91d66ff2
5
5
  SHA512:
6
- metadata.gz: 41b6e64b0dacb938aff65776baea13db6b1de7eb209104823bd1498d6a58368984c0e8c01a2140af38d47c16d50d6552f3978c8c83420034ba88494ba8dd8a63
7
- data.tar.gz: 6c5f2fccb3d3755bfc22af75d903e15afcaa1fd720ed4666618817f27e6d6d5592dfe453885d71a9aeacbf57af8e66698a0d14f520ce95c38d942d00f35b39b1
6
+ metadata.gz: 3b24ea60d59cfe2a2b0740dd373480677fdacce3cfa2e776a3753533f3a09c160f82a8a72d89e487f8550c9ecf9617fa35fd19cd7d3943b157af679cef7bbf21
7
+ data.tar.gz: 4154adddd34af2fe8108536b41d5d960f683cae47996fcee64dd7e81f400eb02c7ce0133684dd6a2f8a9073b1bfb9fc7c4e6f9aa3ca431dab96c60d91ce68221
@@ -0,0 +1,33 @@
1
+ name: Release gem
2
+
3
+ on:
4
+ workflow_dispatch:
5
+ inputs:
6
+ rubygems-otp-code:
7
+ description: RubyGems OTP code
8
+ required: true
9
+
10
+ permissions:
11
+ contents: write
12
+
13
+ jobs:
14
+ release-gem:
15
+ runs-on: ubuntu-latest
16
+ env:
17
+ GEM_HOST_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }}
18
+ GEM_HOST_OTP_CODE: ${{ github.event.inputs.rubygems-otp-code }}
19
+ steps:
20
+ - uses: actions/checkout@v2
21
+ with:
22
+ fetch-depth: 0 # bundle exec rake release で git tag を見るため、tagをfetchするようにしている
23
+ - uses: ruby/setup-ruby@v1
24
+ with:
25
+ ruby-version: 3.1.1
26
+ - name: Bundle install
27
+ run: bundle install
28
+ - name: Setup git config # bundle exec rake release でgit tagが打たれていない場合、タグを打ってpushしてくれるため用意している
29
+ run: |
30
+ git config --global user.email "taka0125@gmail.com"
31
+ git config --global user.name "Takahiro Ooishi"
32
+ - name: Release gem
33
+ run: bundle exec rake release
@@ -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
@@ -7,5 +7,6 @@ spec/dummy/log/*.log
7
7
  spec/dummy/tmp/
8
8
 
9
9
  vendor/bundle
10
+ vendor/bin
10
11
  Gemfile.lock
11
12
 
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
- [![Circle CI](https://circleci.com/gh/moromi/moromi-error.svg?style=svg)](https://circleci.com/gh/moromi/moromi-error)
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)
@@ -0,0 +1,9 @@
1
+ {
2
+ status: status,
3
+ title: title,
4
+ code: exception.code,
5
+ detail_url: exception.detail_url,
6
+ debug_message: exception.debug_message,
7
+ error_title: exception.error_title,
8
+ errors: exception.errors
9
+ }
@@ -1,6 +1,7 @@
1
1
  json.status status
2
- json.code exception.code
3
2
  json.title title
4
- json.store_url exception.store_url
3
+ json.code exception.code
4
+ json.detail_url exception.detail_url
5
5
  json.debug_message exception.debug_message
6
+ json.error_title exception.error_title
6
7
  json.errors exception.errors
@@ -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
- copy_json_templates
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 copy_json_templates
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
@@ -5,7 +5,9 @@ module Moromi
5
5
 
6
6
  config_accessor :debug
7
7
  config_accessor :logger
8
- config_accessor :store_url
8
+ config_accessor :information_builder_klass
9
+ config_accessor :severity_mappings
10
+ config_accessor :use_exception_notifier
9
11
  end
10
12
  end
11
13
  end
@@ -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
- return if exception.is_a? Moromi::Error::Default
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
- messages = []
10
- messages << ([exception.inspect] + (exception&.backtrace || [])).compact.join("\n").gsub("\n", '\n')
64
+ def fetch_errors(exception)
65
+ return [exception.inspect] unless exception.respond_to?(:errors)
11
66
 
12
- Rails.logger.error(messages.join(' '))
67
+ exception.errors
13
68
  end
14
69
  end
15
70
  end
@@ -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] title
15
+ # @param [String] error_title
14
16
  # @param [Array<String>] errors
15
17
  # @param [String] message
16
18
  # @param [String] debug_message
17
- def initialize(code: nil, title: nil, errors: self.class::DEFAULT_ERRORS, message: nil, debug_message: nil)
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 || self.class::DEFAULT_CODE
20
- @title = translate(title || self.class::DEFAULT_TITLE)
21
- @errors = Array(errors).map { |error| translate(error) }
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
- @debug_message || try(:backtrace).try(:first) || ''
58
+
59
+ @debug_message || cleaned_backtrace.first || ''
29
60
  end
30
61
 
31
- # @param [Exception] exception
32
- # @return [Moromi::Error::Default]
33
- def self.make(exception)
34
- return exception if exception.is_a? Default
35
- new(debug_message: exception.message)
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.translate(key, scope: [:strings], default: key.to_s)
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
- if defined?(ActiveRecord::RecordInvalid) && exception.is_a?(ActiveRecord::RecordInvalid)
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
- attr_accessor :store_url
116
+ class TooManyRequests < Default
117
+ DEFAULT_CODE = 10005
118
+ DEFAULT_ERRORS = ['moromi-error.too_many_requests']
86
119
  end
87
120
  end
@@ -0,0 +1,13 @@
1
+ module Moromi
2
+ module Error
3
+ module InformationBuildable
4
+ def initialize(controller)
5
+ raise NotImplementedError
6
+ end
7
+
8
+ def build
9
+ raise NotImplementedError
10
+ end
11
+ end
12
+ end
13
+ end
@@ -5,14 +5,15 @@ 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
11
+ class_attribute :default_moromi_error_template_path
12
12
  class_attribute :default_moromi_error_renderer_options
13
13
  class_attribute :moromi_error_logger
14
14
 
15
- self.default_moromi_error_renderer_options = {partial: ERROR_TEMPLATES[:default], layout: false}
15
+ self.default_moromi_error_template_path = ERROR_TEMPLATES[:default]
16
+ self.default_moromi_error_renderer_options = {layout: false}
16
17
  self.moromi_error_logger = Moromi::Error::DefaultLogger.new
17
18
  end
18
19
 
@@ -40,14 +41,26 @@ module Moromi::Error
40
41
  render_error(410, 'Gone', exception, options: options, locals: locals)
41
42
  end
42
43
 
44
+ def render_too_many_requests(exception: Moromi::Error::Default.new, options: nil, locals: {})
45
+ render_error(429, 'Too Many Requests', exception, options: options, locals: locals)
46
+ end
47
+
43
48
  def render_force_update(exception: Moromi::Error::NeedForceUpdate.new, options: nil, locals: {})
44
- options = options || {partial: ERROR_TEMPLATES[:force_update], layout: false}
45
49
  render_bad_request(exception: exception, options: options, locals: locals)
46
50
  end
47
51
 
52
+ def render_internal_server_error(exception: Moromi::Error::Default.new, options: nil, locals: {})
53
+ render_error(500, 'Internal Server Error', exception, options: options, locals: locals)
54
+ end
55
+
56
+ def render_service_unavailable(exception: Moromi::Error::Default.new, options: nil, locals: {})
57
+ render_error(503, 'Service Unavailable', exception, options: options, locals: locals)
58
+ end
59
+
48
60
  private
49
61
 
50
- def render_error(status, title, exception, options: nil, locals: {})
62
+ def render_error(status, title, exception, options: nil, template_path: nil, locals: {})
63
+ template_path ||= self.class::default_moromi_error_template_path
51
64
  options = options || self.class::default_moromi_error_renderer_options
52
65
  e = Moromi::Error::Default.make(exception)
53
66
 
@@ -57,13 +70,15 @@ module Moromi::Error
57
70
  locals = {status: status, title: title, exception: e}.merge(locals)
58
71
 
59
72
  render_block = -> {
60
- render options.merge({locals: locals})
73
+ render template_path, **options, locals: locals
61
74
  }
62
75
 
63
76
  respond_to do |format|
64
77
  format.html &render_block
65
78
  format.json &render_block
66
79
  end
80
+ rescue ActionController::UnknownFormat
81
+ render status: 406, body: "Not Acceptable"
67
82
  end
68
83
  end
69
84
  end
@@ -4,12 +4,16 @@ module Moromi
4
4
  extend ActiveSupport::Concern
5
5
 
6
6
  included do
7
- rescue_from Moromi::Error::Default, with: -> (e) { render_bad_request(exception: e) }
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::NeedForceUpdate, with: -> (e) { e.store_url = Moromi::Error.config.store_url; render_force_update(exception: e) }
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
@@ -1,5 +1,5 @@
1
1
  module Moromi
2
2
  module Error
3
- VERSION = "0.2.0"
3
+ VERSION = "0.5.0"
4
4
  end
5
5
  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.store_url = ''
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/moromi-error.gemspec CHANGED
@@ -19,14 +19,15 @@ 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.3'
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', '>= 5.2'
26
25
 
27
- spec.add_development_dependency "bundler", "~> 1.12"
28
- spec.add_development_dependency "rake", "~> 10.0"
29
- spec.add_development_dependency "rspec", "~> 3.0"
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
+ spec.add_development_dependency "sprockets-rails"
32
33
  end