minato_error_handler 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: fc543ada4f565f9bfa76c2eba17eea4c7cddf8c587fb4a3e686a6424e3a7b8fa
4
+ data.tar.gz: 1ed085ad3783fa4c05774759c71d8f8e9996d8d1804aa0f5cce3a9ae60474e2e
5
+ SHA512:
6
+ metadata.gz: 92b2590329c0f2d92eb343c76e79bf38cb8c9d599033e3ea2db80e83753d12a4c156222033519485d96bb3c275ef8730141ee25abb094c9d0871c4724cec9866
7
+ data.tar.gz: 36e207a8be34f6d67fa0c3da6f6e50178041bb9f7ad432699951efe36b2e61aaa08512f07daf395128341a3bb093bc56c9287d456573329d4087d823257df2b0
@@ -0,0 +1,39 @@
1
+
2
+ {
3
+ "name": "${localWorkspaceFolderBasename}",
4
+ "dockerComposeFile": [
5
+ "../compose.yml",
6
+ "docker-compose.yml"
7
+ ],
8
+ "service": "minato-error-handler-rails",
9
+ "workspaceFolder": "/usr/src/api",
10
+ "features": {
11
+ "ghcr.io/devcontainers/features/common-utils:2": {},
12
+ "ghcr.io/devcontainers-contrib/features/zsh-plugins:0": {
13
+ "plugins": "zsh-autosuggestions zsh-syntax-highlighting",
14
+ "omzPlugins": "https://github.com/zsh-users/zsh-autosuggestions https://github.com/zsh-users/zsh-syntax-highlighting"
15
+ },
16
+ "ghcr.io/stuartleeks/dev-container-features/shell-history:0": {},
17
+ "ghcr.io/guiyomh/features/vim:0": {},
18
+ "ghcr.io/devcontainers/features/git:1": {}
19
+ },
20
+ "customizations": {
21
+ "vscode": {
22
+ "extensions": [
23
+ "eamodio.gitlens",
24
+ "redhat.vscode-yaml",
25
+ "EditorConfig.EditorConfig",
26
+ "GitLab.gitlab-workflow",
27
+ "MS-vsliveshare.vsliveshare"
28
+ ],
29
+ "settings": {
30
+ "terminal.integrated.defaultProfile.linux": "zsh",
31
+ "terminal.integrated.defaultProfile.windows": "zsh",
32
+ "terminal.integrated.defaultProfile.osx": "zsh"
33
+ }
34
+ }
35
+ },
36
+ "postCreateCommand": "bundle config --local GITLAB__COM gitlab-ci-token:$GITLAB_AUTH_TOKEN",
37
+ "postStartCommand": "bundle install",
38
+ "remoteUser": "ruby"
39
+ }
@@ -0,0 +1,9 @@
1
+ version: '3.8'
2
+
3
+ services:
4
+ minato-error-handler-rails:
5
+ volumes:
6
+ - .:/usr/src/api:cached
7
+ entrypoint: []
8
+ command: /bin/sh -c "while sleep 1000; do :; done"
9
+
data/.editorconfig ADDED
@@ -0,0 +1,12 @@
1
+ # EditorConfig is awesome: https://EditorConfig.org
2
+
3
+ # top-most EditorConfig file
4
+ root = true
5
+
6
+ [*]
7
+ indent_style = space
8
+ indent_size = 2
9
+ end_of_line = lf
10
+ charset = utf-8
11
+ trim_trailing_whitespace = true
12
+ insert_final_newline = true
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,27 @@
1
+ require:
2
+ - rubocop-rake
3
+ - rubocop-rspec
4
+
5
+ AllCops:
6
+ NewCops: enable
7
+ TargetRubyVersion: 2.6
8
+ Exclude:
9
+ - spec/dummy/**/*
10
+ - vendor/**/*
11
+
12
+ Style/StringLiterals:
13
+ Enabled: true
14
+ EnforcedStyle: double_quotes
15
+
16
+ Style/StringLiteralsInInterpolation:
17
+ Enabled: true
18
+ EnforcedStyle: double_quotes
19
+
20
+ Style/Documentation:
21
+ Enabled: false
22
+
23
+ Layout/LineLength:
24
+ Max: 120
25
+
26
+ RSpec/AnyInstance:
27
+ Enabled: false
data/Dockerfile ADDED
@@ -0,0 +1 @@
1
+ FROM us-east1-docker.pkg.dev/minato-cloud/images/ruby-minato:1.0.0-dev
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Siderlan Santos
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # minato-error-handler-rails
2
+
3
+ TODO: Delete this and the text below, and describe your gem
4
+
5
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/minato_error_handler`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+
7
+ ## Installation
8
+
9
+ TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
+
11
+ Install the gem and add to the application's Gemfile by executing:
12
+
13
+ $ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
14
+
15
+ If bundler is not being used to manage dependencies, install the gem by executing:
16
+
17
+ $ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Development
24
+
25
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
26
+
27
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
28
+
29
+ ## License
30
+
31
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(spec: "app:db:test:prepare")
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
data/compose.yml ADDED
@@ -0,0 +1,11 @@
1
+ services:
2
+ minato-error-handler-rails:
3
+ environment:
4
+ GITLAB_AUTH_TOKEN: ${GITLAB_AUTH_TOKEN}
5
+ build: .
6
+ volumes:
7
+ - .:/usr/src/api
8
+ - bundle:/home/rails/.bundle
9
+
10
+ volumes:
11
+ bundle:
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "minato_logger"
4
+
5
+ module MinatoErrorHandler
6
+ module ErrorHandler
7
+ extend ActiveSupport::Concern
8
+
9
+ included do
10
+ rescue_from StandardError, with: :handle
11
+ end
12
+
13
+ private
14
+
15
+ def handle(exception)
16
+ error = MinatoErrorHandler::MinatoError.from_error(exception)
17
+ report_error(error)
18
+ render json: { errors: [error.to_json] }, status: error.status_code
19
+ end
20
+
21
+ def report_error(error)
22
+ logger = MinatoLogger::Logger.new
23
+ logger.error(error.to_json)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "securerandom"
4
+ require "json"
5
+
6
+ module MinatoErrorHandler
7
+ class MinatoError < StandardError
8
+ def initialize(details: {}, caused_by: nil, status_code: 500)
9
+ @caused_by = caused_by
10
+ @details = details
11
+ @status_code = status_code
12
+ super
13
+ end
14
+
15
+ def self.from_error(error)
16
+ return error if error.instance_of?(MinatoErrorHandler::MinatoError)
17
+
18
+ new caused_by: error.cause
19
+ end
20
+
21
+ attr_reader :details, :status_code
22
+
23
+ def message
24
+ "An unknow error has occurred!"
25
+ end
26
+
27
+ def code
28
+ self.class.name
29
+ end
30
+
31
+ def unique_identfier
32
+ @unique_identfier || SecureRandom.uuid
33
+ end
34
+
35
+ def caused_by
36
+ @caused_by || cause
37
+ end
38
+
39
+ def serialized_hash
40
+ { message: message, code: code, unique_identfier: unique_identfier,
41
+ details: details, caused_by: caused_by, status_code: status_code }
42
+ end
43
+
44
+ def to_json(*_args)
45
+ serialized_hash.to_json
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MinatoErrorHandler
4
+ class NetworkError < MinatoErrorHandler::MinatoError
5
+ def initialize(details: {}, caused_by: nil, status_code: nil, request_body: {})
6
+ @request_body = request_body
7
+ super(details: details, caused_by: caused_by, status_code: status_code)
8
+ end
9
+
10
+ attr_reader :request_body
11
+
12
+ def message
13
+ "A network error has occurred!"
14
+ end
15
+
16
+ def serialized_hash
17
+ super.merge({ request_body: request_body })
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails"
4
+
5
+ module MinatoErrorHandler
6
+ class Railtie < ::Rails::Railtie
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MinatoErrorHandler
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "minato_error_handler/railtie"
4
+ require "minato_error_handler/version"
5
+ require "minato_error_handler/minato_error"
6
+ require "minato_error_handler/network_error"
7
+ require "minato_error_handler/error_handler"
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/minato_error_handler/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "minato_error_handler"
7
+ spec.version = MinatoErrorHandler::VERSION
8
+ spec.authors = ["Ferreri"]
9
+ spec.email = ["contato@ferreri.co"]
10
+
11
+ spec.summary = "Error reporting for Minato Rails Apps."
12
+ spec.homepage = "https://gitlab.com/ferreri/minato/minato_error_handler"
13
+ spec.license = "MIT"
14
+ spec.required_ruby_version = ">= 2.6.0"
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = "https://gitlab.com/ferreri/minato/minato_error_handler"
18
+ spec.metadata["changelog_uri"] = "https://gitlab.com/ferreri/minato/minato_error_handler/-/blob/main/CHANGELOG.md?ref_type=heads"
19
+ # rubocop:disable Gemspec/RequireMFA
20
+ spec.metadata["rubygems_mfa_required"] = "false"
21
+ # rubocop:enable Gemspec/RequireMFA
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(__dir__) do
26
+ `git ls-files -z`.split("\x0").reject do |f|
27
+ (File.expand_path(f) == __FILE__) ||
28
+ f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor Gemfile])
29
+ end
30
+ end
31
+ spec.bindir = "exe"
32
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
33
+ spec.require_paths = ["lib"]
34
+
35
+ spec.add_dependency "minato_logger", "~>0.1.6"
36
+ spec.add_dependency "rails", ">= 7.0.4"
37
+
38
+ # Uncomment to register a new dependency of your gem
39
+ # spec.add_dependency "example-gem", "~> 1.0"
40
+
41
+ # For more information and examples about making a new gem, check out our
42
+ # guide at: https://bundler.io/guides/creating_gem.html
43
+ end
@@ -0,0 +1,4 @@
1
+ module MinatoErrorHandler
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: minato_error_handler
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ferreri
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-11-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: minato_logger
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.1.6
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.1.6
27
+ - !ruby/object:Gem::Dependency
28
+ name: rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 7.0.4
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 7.0.4
41
+ description:
42
+ email:
43
+ - contato@ferreri.co
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".devcontainer/devcontainer.json"
49
+ - ".devcontainer/docker-compose.yml"
50
+ - ".editorconfig"
51
+ - ".rspec"
52
+ - ".rubocop.yml"
53
+ - Dockerfile
54
+ - LICENSE.txt
55
+ - README.md
56
+ - Rakefile
57
+ - compose.yml
58
+ - lib/minato_error_handler.rb
59
+ - lib/minato_error_handler/error_handler.rb
60
+ - lib/minato_error_handler/minato_error.rb
61
+ - lib/minato_error_handler/network_error.rb
62
+ - lib/minato_error_handler/railtie.rb
63
+ - lib/minato_error_handler/version.rb
64
+ - minato_error_handler.gemspec
65
+ - sig/minato_error_handler.rbs
66
+ homepage: https://gitlab.com/ferreri/minato/minato_error_handler
67
+ licenses:
68
+ - MIT
69
+ metadata:
70
+ homepage_uri: https://gitlab.com/ferreri/minato/minato_error_handler
71
+ source_code_uri: https://gitlab.com/ferreri/minato/minato_error_handler
72
+ changelog_uri: https://gitlab.com/ferreri/minato/minato_error_handler/-/blob/main/CHANGELOG.md?ref_type=heads
73
+ rubygems_mfa_required: 'false'
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 2.6.0
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubygems_version: 3.1.6
90
+ signing_key:
91
+ specification_version: 4
92
+ summary: Error reporting for Minato Rails Apps.
93
+ test_files: []