error_response 0.2.0 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bfd7efb20d85b835e242e64e7fee3d633522eefbe1834aedf30295b84b2cfea8
4
- data.tar.gz: 9e9013875242b545811ce64585d3cf8f58a33775d773b507125e7cd8934bbaca
3
+ metadata.gz: cc3fa7849140a231dbc285ef371838efe21a45ec99ae156524a0f54bef763300
4
+ data.tar.gz: e586365e16c38a5283dd20949d173262710cc1f04102b2e5a5da313a5ae524ff
5
5
  SHA512:
6
- metadata.gz: ba3d15d0cd86e5fea18fba693fef5b75fae6b8ba409a73b4d377cfa85e45e70d4cf87b116c6c3e78238cb16c047b8da10943b09abe33ece451a24aa83b462deb
7
- data.tar.gz: 0aafe71739e97cd17b3fadb3614cf7c3e9fc6a221d77bab5a6bc4960d6e2374c3f9f881756153d333e59078049560268df4e290891d1ba1e4a9276bc263f1df1
6
+ metadata.gz: 97c32d812b6815bae358426cec75d0e5f6bb8872e05e282de3bc43a3c0d0be6c38e72ce99cf1de4df5bd8177cd9a64cbf77db93817a93f7230d13dc9606d9a4b
7
+ data.tar.gz: 553814f93c8bfdb03149f4eaf76c9fbe5b39307eab899941b56f5d840c6ae2044b9c08035ed0036dbc7d6d4f4b504cd5ed9d263cdd30732f8bc46e607d11c74b
@@ -1,21 +1,24 @@
1
1
  require 'yaml'
2
2
  class ErrorResponse
3
- GEM_ROOT = File.expand_path("../..", __FILE__)
4
- YAML_PATH = 'lib/error_response.yml'
5
- EXTEND_DIR = 'lib/error_response/*.yml'
3
+ YAML_PATH = 'config/error_response.yml'
6
4
 
7
5
  def self.to_api(key, message=nil)
8
- err_json = yaml_hash[key.to_s] || {'error_code' => 500000, 'error_message' => message}
6
+ err_json = yaml_hash[key.to_s]&.dup
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
9
12
 
10
13
  status = err_json['error_code'] / 1000
11
14
  {
12
- 'status' => status,
13
- 'json' => err_json
15
+ status: status,
16
+ json: err_json
14
17
  }
15
18
  end
16
19
 
17
20
  def self.to_hash(key)
18
- yaml_hash[key.to_s]
21
+ yaml_hash[key.to_s] || {}
19
22
  end
20
23
 
21
24
  def self.all
@@ -24,14 +27,6 @@ class ErrorResponse
24
27
 
25
28
  private
26
29
  def self.yaml_hash
27
- return @hash unless @hash.nil?
28
-
29
- @hash = YAML.load_file(File.join(GEM_ROOT,YAML_PATH))
30
- Dir.glob(EXTEND_DIR).each do |file|
31
- extend_yml = YAML.load_file(file)
32
- @hash.merge!(extend_yml)
33
- end
34
-
35
- @hash
30
+ @hash ||= YAML.load_file(YAML_PATH)
36
31
  end
37
32
  end
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.0
4
+ version: 0.2.5
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-19 00:00:00.000000000 Z
11
+ date: 2020-01-08 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: use for error_response
14
14
  email: jameslee@kdanmobile.com
@@ -17,7 +17,6 @@ extensions: []
17
17
  extra_rdoc_files: []
18
18
  files:
19
19
  - lib/error_response.rb
20
- - lib/error_response.yml
21
20
  homepage: https://github.com/kdan-mobile-software-ltd/error_response
22
21
  licenses:
23
22
  - MIT
@@ -37,7 +36,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
37
36
  - !ruby/object:Gem::Version
38
37
  version: '0'
39
38
  requirements: []
40
- rubygems_version: 3.0.4
39
+ rubygems_version: 3.0.6
41
40
  signing_key:
42
41
  specification_version: 4
43
42
  summary: A tool for API error response
@@ -1,45 +0,0 @@
1
- wrong_email:
2
- error_code: 400_001
3
- error_message: user email not correct
4
- wrong_password:
5
- error_code: 400_002
6
- error_message: user password not correct
7
- verify_receipt_failed:
8
- error_code: 400_003
9
- error_message: receipt verify failed
10
- resend_confirmation_failed:
11
- error_code: 400_004
12
- error_message: confirmation mail resend failed
13
- reset_password_failed:
14
- error_code: 400_005
15
- error_message: reset password failed
16
- upload_video_failed:
17
- error_code: 400_060
18
- error_message: upload video failed
19
- theme_not_found:
20
- error_code: 400_061
21
- error_message: current theme is not found
22
- client_not_found:
23
- error_code: 403_001
24
- error_message: door_keeper client not found
25
- access_token_invalid:
26
- error_code: 403_002
27
- error_message: door_keeper access_token invalid
28
- user_forbidden:
29
- error_code: 403_003
30
- error_message: not enough privilege to access data
31
- provider_not_allow:
32
- error_code: 403_004
33
- error_message: third-party provider is not allow
34
- third_party_missing_email:
35
- error_code: 403_005
36
- error_message: third party login is missing email
37
- email_existed:
38
- error_code: 409_001
39
- error_message: email already existed
40
- email_confirmed:
41
- error_code: 409_002
42
- error_message: email already confirmed
43
- preview_processing:
44
- error_code: 418_001
45
- error_message: preview processing, please try it later