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.
- checksums.yaml +4 -4
- data/lib/error_response.rb +19 -24
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a542fc68200b61b3f071fcc379cabbf154571c3e3bb732e1a9cf68d0ad416744
|
4
|
+
data.tar.gz: 64c340f79364c03c296e6082edefabb8451af5a3878925db99f9994dc82d025e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a03d605b108bcf3cd152d95980160f36d35ce08423fb0522bfc34c72cb7b1469b3160bb5bbee7051b53b4b87a4881abafdefc0bdc1383c3207cf5c4fdc6f81f9
|
7
|
+
data.tar.gz: 523b24c397f90dcd07f253556bc97ffc807ccf55a1a6790906bda169d7ad7b0dc112c5701783b08fb771c130b05eb55b47b01427012c20e025d8919bf637e6de
|
data/lib/error_response.rb
CHANGED
@@ -2,38 +2,33 @@ require 'yaml'
|
|
2
2
|
class ErrorResponse
|
3
3
|
YAML_PATH = 'config/error_response.yml'
|
4
4
|
|
5
|
-
def self.
|
6
|
-
|
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
|
-
|
23
|
-
|
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.
|
32
|
-
|
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
|