error_response 0.2.4 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/error_response.rb +19 -17
  3. metadata +5 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c2bffc5e8ad94e430ac4e12de4670f3de41f3ee29d1912ff74b20a228869da54
4
- data.tar.gz: ac9b4d2a3345caf6651e745c6f4deab4476a8ceb5fc234fe04e080f8d5173afe
3
+ metadata.gz: a542fc68200b61b3f071fcc379cabbf154571c3e3bb732e1a9cf68d0ad416744
4
+ data.tar.gz: 64c340f79364c03c296e6082edefabb8451af5a3878925db99f9994dc82d025e
5
5
  SHA512:
6
- metadata.gz: aa3c405b6dd31b1eb09fb59d7a72296b9f85144de3da26c3cce84b0a0d6a8879fa44318dfe841fc00baf2e89efc3d37906f204a870a35248bc49a717b1ec4f59
7
- data.tar.gz: 61d25463d13501d958c31193c51a943c6b6fae3b2f5953c7091e6e1f0a50d5a0a67a233583bfb85f2dd7018a39f522d61fe0261c8da739b3b199afa2b34b01fc
6
+ metadata.gz: a03d605b108bcf3cd152d95980160f36d35ce08423fb0522bfc34c72cb7b1469b3160bb5bbee7051b53b4b87a4881abafdefc0bdc1383c3207cf5c4fdc6f81f9
7
+ data.tar.gz: 523b24c397f90dcd07f253556bc97ffc807ccf55a1a6790906bda169d7ad7b0dc112c5701783b08fb771c130b05eb55b47b01427012c20e025d8919bf637e6de
@@ -2,31 +2,33 @@ require 'yaml'
2
2
  class ErrorResponse
3
3
  YAML_PATH = 'config/error_response.yml'
4
4
 
5
- def self.to_api(key, message=nil)
6
- err_json = yaml_hash[key.to_s]
7
- if err_json.nil?
8
- err_json = {'error_code' => 500000, 'error_message' => message}
9
- elsif !message.nil?
10
- err_json['error_message'] += ": #{message}"
11
- end
12
-
13
- status = err_json['error_code'] / 1000
14
- {
15
- status: status,
16
- json: err_json
17
- }
5
+ def self.all
6
+ yaml_hash
18
7
  end
19
8
 
20
9
  def self.to_hash(key)
21
- yaml_hash[key.to_s] || {}
10
+ return unless yaml_hash.key?(key.to_s)
11
+ yaml_hash[key.to_s].merge({ 'error_key' => key.to_s })
22
12
  end
23
13
 
24
- def self.all
25
- yaml_hash
14
+ def self.to_api(key, message=nil)
15
+ default_result = {
16
+ status: 500,
17
+ json: { 'error_code' => 500_000, 'error_message' => message }
18
+ }
19
+ return default_result unless yaml_hash.key?(key.to_s)
20
+
21
+ json = yaml_hash[key.to_s].merge({ 'error_key' => key.to_s })
22
+ json['error_message'] += ": #{message}" unless message.nil?
23
+ {
24
+ status: json['error_code'] / 1_000,
25
+ json: json
26
+ }
26
27
  end
27
28
 
28
29
  private
30
+
29
31
  def self.yaml_hash
30
32
  @hash ||= YAML.load_file(YAML_PATH)
31
33
  end
32
- end
34
+ end
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: error_response
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
- - jameslee
7
+ - Kdan Mobile Software Developer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-08 00:00:00.000000000 Z
11
+ date: 2020-08-17 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: use for error_response
14
- email: jameslee@kdanmobile.com
14
+ email: dev@kdanmobile.com
15
15
  executables: []
16
16
  extensions: []
17
17
  extra_rdoc_files: []
@@ -36,7 +36,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
36
36
  - !ruby/object:Gem::Version
37
37
  version: '0'
38
38
  requirements: []
39
- rubygems_version: 3.0.1
39
+ rubygems_version: 3.0.3
40
40
  signing_key:
41
41
  specification_version: 4
42
42
  summary: A tool for API error response