error_response 0.2.1 → 0.2.6

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 +16 -4
  3. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 49fd3944b8d8d387a0d8894b4200f587e53778d1c30fa72b60c11525efebf8b7
4
- data.tar.gz: 7bd468da83c09e2bfe9bde84f3021e5e5757c5943c0c570fc321f50fcfeae622
3
+ metadata.gz: a0f90a8aea1f1e2d6f12af804b4ae00a5ccd94b28dbb5a6ffd43409fa146c430
4
+ data.tar.gz: 8c7beb929a1b26a171620e5775821f826bd20ecf4a472dda785935c07f90863f
5
5
  SHA512:
6
- metadata.gz: 6827910973f2459448fb5e6a864f786ff7a797c80871e1452239f72d9deb95ec4287a980892ad9c0651ff85824186cfbedaa10c352ce42f3b6a711b87f7a6f62
7
- data.tar.gz: bbbce4540ca67c69bab4e0318d35a9e5d892de689061861ccb4de958490986f1c7ad90cc335b6ebcebca7cff320e2e64107ed5ad085d8514cc97ff4f6c8f2cd0
6
+ metadata.gz: 2bc4768ae9f29f625c921f780e0d8149d880b531d16910f637ed889ec38a3f98ef3bc00522d1d295ed7b856924561181bd6db9a9b418d7aa94dc7228b0fb2487
7
+ data.tar.gz: '019c8cf0ff9b531903520730ec3af687a93543c0d95700e030525e46e3867313d76549477e50b57edae5b4a785ef507c653e638a9711a1bd9ec37099bbf90495'
@@ -3,17 +3,29 @@ class ErrorResponse
3
3
  YAML_PATH = 'config/error_response.yml'
4
4
 
5
5
  def self.to_api(key, message=nil)
6
- err_json = yaml_hash[key.to_s] || {'error_code' => 500000, 'error_message' => message}
6
+ err_json = yaml_hash[key.to_s]&.dup
7
+ err_json['error_key'] = key.to_s if !err_json.nil? && !key.nil? && yaml_hash.key?(key.to_s)
8
+ if err_json.nil?
9
+ err_json = {'error_code' => 500000, 'error_message' => message}
10
+ elsif !message.nil?
11
+ err_json['error_message'] += ": #{message}"
12
+ end
7
13
 
8
14
  status = err_json['error_code'] / 1000
9
15
  {
10
- 'status' => status,
11
- 'json' => err_json
16
+ status: status,
17
+ json: err_json
12
18
  }
13
19
  end
14
20
 
15
21
  def self.to_hash(key)
16
- yaml_hash[key.to_s]
22
+ if yaml_hash.key?(key.to_s)
23
+ result = yaml_hash[key.to_s]
24
+ result['error_key'] = key.to_s
25
+ else
26
+ result = nil
27
+ end
28
+ result
17
29
  end
18
30
 
19
31
  def self.all
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: error_response
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - jameslee
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-08-20 00:00:00.000000000 Z
11
+ date: 2020-08-14 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: use for error_response
14
14
  email: jameslee@kdanmobile.com
@@ -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.4
39
+ rubygems_version: 3.0.3
40
40
  signing_key:
41
41
  specification_version: 4
42
42
  summary: A tool for API error response