json_api_toolbox 0.12.1 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c35234d994ec95480c6c0c96e5db8d413d878887
4
- data.tar.gz: 2ff74bea5ad4f9dc634bcb7dd20a73b2b18786bf
3
+ metadata.gz: 73b91ef1e5dadc1e481b783fe817242c60c340d9
4
+ data.tar.gz: 6ab51aa214846f0d6100ba92529bce53abfcfa3a
5
5
  SHA512:
6
- metadata.gz: b691f35cf10e21d4378a2eac9388fc76191d0cb4fcb3db3ad2eddc78acaabd14db41169a37236a9c5ecacf1a3bb5ac2914d60ccf4929019acd962a02191d6b77
7
- data.tar.gz: 789eec7fe490605780dff1c5bbcf3fea7315e89f8ea92284ed138b722ab00a371ed73da59c1c262d77c1b4d8a743b9fcb596fb5445367344395631b50cd1ddcc
6
+ metadata.gz: 50155433bc66dd3e51a60c59e1210a7e84a83514c9cf2730c537ce00c394b4c08ba9846ec9ff194e8b9df1d224a8cac0c5c68a4ece3cae1507a55e4ddf98b838
7
+ data.tar.gz: 0a9510a7c553e0ac321e160b1510e93c7d41e0ade07e710fe64f305d576496fb1788a097a31dfb152668c2a729620683112648552e9d1e8f65caec3cdda0ad21
data/CHANGELOG.md CHANGED
@@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.12.2] - 2018-05-02
10
+ ### Changed
11
+ - Added error details on exception renderizable
12
+ - Added exception log
13
+
9
14
  ## [0.12.1] - 2018-04-04
10
15
  ### Changed
11
16
  - Bug fix proxy at Service class
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JsonApiToolbox
4
- VERSION = '0.12.1'
4
+ VERSION = '0.13.0'
5
5
  end
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'active_support'
4
- require 'pry'
5
4
 
6
5
  module JsonApiToolbox
7
6
  module RenderizableExceptions
@@ -12,16 +11,38 @@ module JsonApiToolbox
12
11
  end
13
12
 
14
13
  def render_any_exception(exception)
15
- render(
16
- jsonapi_errors: {
17
- title: exception.class.to_s,
14
+ puts_build_log_error(exception)
15
+
16
+ render build_jsonapi(exception)
17
+ end
18
+
19
+ def build_jsonapi(exception)
20
+ { jsonapi_errors:
21
+ { title: exception.class.to_s,
18
22
  detail: exception.message,
19
- source: {}
20
- },
23
+ status: 500,
24
+ code: code(exception),
25
+ source: {} },
21
26
  jsonapi_class: {
22
27
  class: { Hash: JsonApiToolbox::Serializables::SerializableException }
23
- }
24
- )
28
+ } }
29
+ end
30
+
31
+ def puts_build_log_error(error)
32
+ puts messages: error.try(:message), trace: error.try(:backtrace)
33
+ end
34
+
35
+ def code(exception)
36
+ model_errors_code(exception) ||
37
+ exception.try(:code) ||
38
+ 'default_error'
39
+ end
40
+
41
+ def model_errors_code(error)
42
+ detail_error = error.try(:detail)
43
+ detail_error.try(:map, &:flatten).try(:map) do |item|
44
+ [item[0], item[1]['error']].join('_error_')
45
+ end
25
46
  end
26
47
  end
27
48
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json_api_toolbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.1
4
+ version: 0.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adriano Bacha
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-04 00:00:00.000000000 Z
11
+ date: 2018-05-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack