error_response 0.2.5 → 0.4.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 +26 -17
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 89dfae134289bf7bbcc43d119e0e94bffca2022dcaa82aa32ae62dabf6d016b7
|
4
|
+
data.tar.gz: 8f3b6b890ba7191734fe1d2ae21102149ebb84ca4ee6102b1d608b21357b44ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 06e1f7500a4f97c6448611eb6dea6ea52decf9703aa560805c79ce7d473a025cce114edd1110623d6c6e26669129ccd50513a23be2f638a4d179644838beeada
|
7
|
+
data.tar.gz: 0c9e59ed9a5421fb3fab7ac591df3cc1163ed9eca82dcdcbb395ebf2f101cf47834b5ab3b54b3841a8c27f4b76ee061c9a3c35252197068afea868c11ff56615
|
data/lib/error_response.rb
CHANGED
@@ -1,32 +1,41 @@
|
|
1
1
|
require 'yaml'
|
2
|
+
require 'open-uri'
|
3
|
+
|
2
4
|
class ErrorResponse
|
3
5
|
YAML_PATH = 'config/error_response.yml'
|
4
6
|
|
5
|
-
def self.
|
6
|
-
|
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
|
-
}
|
7
|
+
def self.all
|
8
|
+
yaml_hash
|
18
9
|
end
|
19
10
|
|
20
11
|
def self.to_hash(key)
|
21
|
-
yaml_hash
|
12
|
+
return unless yaml_hash.key?(key.to_s)
|
13
|
+
yaml_hash[key.to_s].merge({ 'error_key' => key.to_s })
|
22
14
|
end
|
23
15
|
|
24
|
-
def self.
|
25
|
-
|
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
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.load_remote(remote_file)
|
32
|
+
content = open(remote_file){|f| f.read}
|
33
|
+
@hash = YAML.load(content)
|
26
34
|
end
|
27
35
|
|
28
36
|
private
|
37
|
+
|
29
38
|
def self.yaml_hash
|
30
39
|
@hash ||= YAML.load_file(YAML_PATH)
|
31
40
|
end
|
32
|
-
end
|
41
|
+
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: 0.4.0
|
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-
|
11
|
+
date: 2020-08-20 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: []
|
@@ -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.
|
39
|
+
rubygems_version: 3.0.3
|
40
40
|
signing_key:
|
41
41
|
specification_version: 4
|
42
42
|
summary: A tool for API error response
|