error_response 0.2.7 → 1.0.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.rb +37 -26
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4337265a4915af5e2401a44cc42d65a309e46152ea9a565a72e8ac2ee4428c6d
|
4
|
+
data.tar.gz: ab9ec645f4cd894f493ba8df370fc944a57e5c464e17da29659ce3193c0e75a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 287974143f9c2c9cd714e9ba26f3f700cf709884cb0af76badc24abab2fdf4edef9d9ef0fd3253bddba16d7dbe026d33d62d1b47a7a9eca1762ffbb20ec7004a
|
7
|
+
data.tar.gz: c808a0de1c3cdd652105a323e1b709dda8a2128c70453015a020158eb80c2733896ce12a6343f1f06c3b6bba44ddd8161d30ad61a7caeed9d60a2ac6b4ec13e4
|
data/lib/error_response.rb
CHANGED
@@ -1,39 +1,50 @@
|
|
1
1
|
require 'yaml'
|
2
|
+
require 'open-uri'
|
3
|
+
|
2
4
|
class ErrorResponse
|
3
|
-
|
5
|
+
SETTING_PATH = 'config/error_response.yml'
|
4
6
|
|
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
|
-
}
|
7
|
+
def self.all
|
8
|
+
yaml_hash
|
19
9
|
end
|
20
10
|
|
21
11
|
def self.to_hash(key)
|
22
|
-
|
23
|
-
|
24
|
-
result['error_key'] = key.to_s
|
25
|
-
else
|
26
|
-
result = nil
|
27
|
-
end
|
28
|
-
result
|
12
|
+
return unless yaml_hash.key?(key.to_s)
|
13
|
+
yaml_hash[key.to_s].merge({ 'error_key' => key.to_s })
|
29
14
|
end
|
30
15
|
|
31
|
-
def self.
|
32
|
-
|
16
|
+
def self.to_api(key, message=nil)
|
17
|
+
default_result = {
|
18
|
+
status: 500,
|
19
|
+
json: { 'error_code' => 500_000, 'error_message' => message }
|
20
|
+
}
|
21
|
+
return default_result unless yaml_hash.key?(key.to_s)
|
22
|
+
|
23
|
+
json = yaml_hash[key.to_s].merge({ 'error_key' => key.to_s })
|
24
|
+
json['error_message'] += ": #{message}" unless message.nil?
|
25
|
+
{
|
26
|
+
status: json['error_code'] / 1_000,
|
27
|
+
json: json
|
28
|
+
}
|
33
29
|
end
|
34
30
|
|
35
31
|
private
|
32
|
+
|
36
33
|
def self.yaml_hash
|
37
|
-
@hash
|
34
|
+
return @hash unless @hash.nil?
|
35
|
+
|
36
|
+
settings = YAML.load(File.read(SETTING_PATH))
|
37
|
+
local_array = settings['source']['local']
|
38
|
+
local_hash = local_array.nil? ? {} : local_array.map { |path| YAML.load_file(path) }.inject(&:merge)
|
39
|
+
|
40
|
+
remote_array = settings['source']['remote']
|
41
|
+
remote_hash = remote_array.nil? ? {} : remote_array.map { |url| build_yaml(url) }.inject(&:merge)
|
42
|
+
|
43
|
+
@hash = local_hash.merge(remote_hash)
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.build_yaml(url)
|
47
|
+
content = open(url){|f| f.read}
|
48
|
+
YAML.load(content)
|
38
49
|
end
|
39
|
-
end
|
50
|
+
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.
|
4
|
+
version: 1.0.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: 2020-08-
|
11
|
+
date: 2020-08-25 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: use for error_response
|
14
|
-
email:
|
14
|
+
email: dev@kdanmobile.com
|
15
15
|
executables: []
|
16
16
|
extensions: []
|
17
17
|
extra_rdoc_files: []
|