error_response 1.0.6 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/error_response/configuration.rb +11 -0
- data/lib/error_response/helper.rb +26 -0
- data/lib/error_response/request_error.rb +13 -0
- data/lib/error_response.rb +21 -3
- metadata +21 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a6481a842281a50cbbd0cd724944835901ae86ee3e94a53ea0006f5956a1bb9
|
4
|
+
data.tar.gz: a5e60809e055f5a384648bde3fa4d6173c8886bd321ad46c2a956a6341245074
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df7e0bfae844c91c6b9fa84e8219f74b14f639aee0351bd348c2c69e4807021482dc669307b0ffc7a10f2ddbf6ff9929524c7b4fa817aafeafb6fcc67bf72692
|
7
|
+
data.tar.gz: becc8d002c3c340d1852e131a92b7d9e6442c58e3f110422b58e359dda5e7f14feb558c5fa522811b613fd582b85b8233a3a637e6b4b0149550fe7f34070f81d
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support'
|
4
|
+
|
5
|
+
module ErrorResponse
|
6
|
+
module Helper
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
included do
|
10
|
+
rescue_from RequestError do |e|
|
11
|
+
error_response(e.key, e.error_message, e.error_data)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def success_response(data = {})
|
16
|
+
render status: 200, json: { data: data }
|
17
|
+
end
|
18
|
+
|
19
|
+
def error_response(key, error_message = nil, error_data = {})
|
20
|
+
render_content = ErrorResponse.to_api(key, error_message).deep_dup
|
21
|
+
render_content[:json].merge!(error_data) if error_data.present? && error_data.is_a?(Hash)
|
22
|
+
render_content[:json].merge!(error_data: error_data) if error_data.present? && error_data.is_a?(Array)
|
23
|
+
render(render_content)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ErrorResponse
|
4
|
+
class RequestError < StandardError
|
5
|
+
attr_reader :key, :error_message, :error_data
|
6
|
+
|
7
|
+
def initialize(key, error_message: nil, error_data: {})
|
8
|
+
@key = key
|
9
|
+
@error_message = error_message
|
10
|
+
@error_data = error_data
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/error_response.rb
CHANGED
@@ -1,10 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'yaml'
|
2
4
|
require 'open-uri'
|
3
5
|
|
4
|
-
|
5
|
-
|
6
|
+
require 'error_response/configuration'
|
7
|
+
require 'error_response/helper'
|
8
|
+
require 'error_response/request_error'
|
9
|
+
|
10
|
+
module ErrorResponse
|
6
11
|
|
7
12
|
class << self
|
13
|
+
attr_accessor :configuration
|
14
|
+
|
15
|
+
def configuration
|
16
|
+
@configuration ||= Configuration.new
|
17
|
+
end
|
18
|
+
|
19
|
+
def configure(&block)
|
20
|
+
yield(configuration)
|
21
|
+
end
|
22
|
+
|
8
23
|
def all
|
9
24
|
yaml_hash
|
10
25
|
end
|
@@ -30,7 +45,7 @@ class ErrorResponse
|
|
30
45
|
def yaml_hash
|
31
46
|
return @hash unless @hash.nil?
|
32
47
|
|
33
|
-
settings = YAML.load(File.read(
|
48
|
+
settings = YAML.load(File.read(configuration.yaml_config_path))
|
34
49
|
local_array = settings['source']['local']
|
35
50
|
local_hash = local_array.nil? ? {} : local_array.map { |path| YAML.load_file(path) }.inject(&:merge)
|
36
51
|
|
@@ -43,6 +58,9 @@ class ErrorResponse
|
|
43
58
|
def build_yaml(url)
|
44
59
|
content = URI.open(url){|f| f.read}
|
45
60
|
YAML.load(content)
|
61
|
+
rescue
|
62
|
+
puts "Load yaml from URL (#{url}) failed."
|
63
|
+
{}
|
46
64
|
end
|
47
65
|
|
48
66
|
def parse_status(error_code)
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: error_response
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kdan Mobile Software Developer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
11
|
+
date: 2023-02-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 6.1.7.2
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 6.1.7.2
|
13
27
|
description: use for error_response
|
14
28
|
email: dev@kdanmobile.com
|
15
29
|
executables: []
|
@@ -17,6 +31,9 @@ extensions: []
|
|
17
31
|
extra_rdoc_files: []
|
18
32
|
files:
|
19
33
|
- lib/error_response.rb
|
34
|
+
- lib/error_response/configuration.rb
|
35
|
+
- lib/error_response/helper.rb
|
36
|
+
- lib/error_response/request_error.rb
|
20
37
|
homepage: https://github.com/kdan-mobile-software-ltd/error_response
|
21
38
|
licenses:
|
22
39
|
- MIT
|
@@ -36,7 +53,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
36
53
|
- !ruby/object:Gem::Version
|
37
54
|
version: '0'
|
38
55
|
requirements: []
|
39
|
-
rubygems_version: 3.
|
56
|
+
rubygems_version: 3.4.6
|
40
57
|
signing_key:
|
41
58
|
specification_version: 4
|
42
59
|
summary: A tool for API error response
|