error_response 0.2.8 → 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 -24
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f5eed589e50b7780b64e7bb326c6d73e971d1ac37e3c0be4d00aa78ab28d7b9c
4
- data.tar.gz: 8e9280cea3e10897368959b1901cd01cb616accc1c9eb835f412c452e1628aaa
3
+ metadata.gz: a542fc68200b61b3f071fcc379cabbf154571c3e3bb732e1a9cf68d0ad416744
4
+ data.tar.gz: 64c340f79364c03c296e6082edefabb8451af5a3878925db99f9994dc82d025e
5
5
  SHA512:
6
- metadata.gz: f855a6bcb29eb546a38d249aa3fade61974fbfd26d6a2085e09127736ad1f077dc8d0653b3184f49de9b9a17df7b0018de8e9192cd100f80fedb989e10e03c4f
7
- data.tar.gz: b36effef06aa210e0653de9418ea8ddf4b6a85ab50819e67df59c28ef3bcf4489f8e5025a98395dca42faa87e28906323abf3223a1963bb91b599bfab70f207a
6
+ metadata.gz: a03d605b108bcf3cd152d95980160f36d35ce08423fb0522bfc34c72cb7b1469b3160bb5bbee7051b53b4b87a4881abafdefc0bdc1383c3207cf5c4fdc6f81f9
7
+ data.tar.gz: 523b24c397f90dcd07f253556bc97ffc807ccf55a1a6790906bda169d7ad7b0dc112c5701783b08fb771c130b05eb55b47b01427012c20e025d8919bf637e6de
@@ -2,38 +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]&.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
13
-
14
- status = err_json['error_code'] / 1000
15
- {
16
- status: status,
17
- json: err_json
18
- }
5
+ def self.all
6
+ yaml_hash
19
7
  end
20
8
 
21
9
  def self.to_hash(key)
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
10
+ return unless yaml_hash.key?(key.to_s)
11
+ yaml_hash[key.to_s].merge({ 'error_key' => key.to_s })
29
12
  end
30
13
 
31
- def self.all
32
- 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
+ }
33
27
  end
34
28
 
35
29
  private
30
+
36
31
  def self.yaml_hash
37
32
  @hash ||= YAML.load_file(YAML_PATH)
38
33
  end
39
- end
34
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: error_response
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.8
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kdan Mobile Software Developer