startback 0.10.0 → 0.10.1

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: 10937b9e7877dd7393837c70185fe245493a35234d66a899efee5fbebb539b75
4
- data.tar.gz: 5fd7234b34b09f875dcf9b21ad819eb5072ffed902ddd08ca6c2e6a68e3ec1df
3
+ metadata.gz: ecd3fca505de294b037fbb0f7e15e9e5242823751169a8b745cd5717b9098945
4
+ data.tar.gz: d0b1546710de2899a9ea246b66a03661f58eea3ec03ba7d4f3c8e95c52d49245
5
5
  SHA512:
6
- metadata.gz: 37df032165dd22b0680f8eaf874bada4810707253e06677c6a80b5d21afc87062643143e5f2b50e0f3adbe48d9df00368bb5f7070068e8458565e0d0fb8f1112
7
- data.tar.gz: 754c4703f78bca862a4a7b2f8d973609ec44fab70368fe6d6d371050c140592a5706720ef0208ac4002ce434d85ad8e4d095d07840cd7993e2cb698cd116da5d
6
+ metadata.gz: b0e1bde2cb31f15eeb777da14a9d22062f7dab45028d9de171c9de12526a4571296591eb208c4ebd6c1059730ef671ca76fea98553e7d618272244c2d4f8b7d3
7
+ data.tar.gz: 47a40ac9677ea5998c8089d6b5ca01b7ef7144810ecdde1163e6286fe41313d8009b723f52c074408aec6c316cacb978a6cfe9179f068ff4fe462e7647b75f8e
@@ -2,8 +2,13 @@ module Startback
2
2
  module Errors
3
3
 
4
4
  class Error < StandardError
5
- class << self
5
+ def initialize(message = nil, causes = nil)
6
+ super(message)
7
+ @causes = Array(causes)
8
+ end
9
+ attr_reader :causes
6
10
 
11
+ class << self
7
12
  def status(code = nil)
8
13
  if code.nil?
9
14
  @code || (superclass.respond_to?(:status) ? superclass.status : 500)
@@ -22,11 +27,19 @@ module Startback
22
27
  msg = super
23
28
  return msg unless msg == self.class.name
24
29
  parts = self.class.name.split('::').last.gsub(/[A-Z]/){|x|
25
- " #{x.downcase}"
30
+ " #{x.downcase}"
26
31
  }.strip.split(" ")
27
32
  parts = parts[0...-1] unless self.class.keep_error
28
33
  parts.join(" ").capitalize
29
34
  end
35
+
36
+ def has_causes?
37
+ causes && !causes.empty?
38
+ end
39
+
40
+ def cause
41
+ causes&.first
42
+ end
30
43
  end
31
44
 
32
45
  class BadRequestError < Error
@@ -3,14 +3,28 @@ module Startback
3
3
  class LogFormatter
4
4
 
5
5
  def call(severity, time, progname, msg)
6
- if msg[:error] && msg[:error].respond_to?(:message, true)
7
- msg[:backtrace] = msg[:error].backtrace[0..25] if severity == "FATAL"
8
- msg[:error] = msg[:error].message
9
- end
10
6
  {
11
7
  severity: severity,
12
- time: time,
13
- }.merge(msg).to_json << "\n"
8
+ time: time
9
+ }.merge(msg)
10
+ .merge(error: error_to_json(msg[:error], severity))
11
+ .compact
12
+ .to_json << "\n"
13
+ end
14
+
15
+ def error_to_json(error, severity = nil)
16
+ return error if error.nil?
17
+ return error if error.is_a?(String)
18
+ return error.to_s unless error.is_a?(Exception)
19
+
20
+ backtrace = error.backtrace[0..25] if severity == "FATAL"
21
+ causes = error.causes.map{|c| error_to_json(c) } if error.respond_to?(:causes)
22
+ causes = nil if causes && causes.empty?
23
+ {
24
+ message: error.message,
25
+ backtrace: backtrace,
26
+ causes: causes
27
+ }.compact
14
28
  end
15
29
 
16
30
  end # class LogFormatter
@@ -2,7 +2,7 @@ module Startback
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 10
5
- TINY = 0
5
+ TINY = 1
6
6
  end
7
7
  VERSION = "#{Version::MAJOR}.#{Version::MINOR}.#{Version::TINY}"
8
8
  end
@@ -34,10 +34,25 @@ module Startback
34
34
  # A bit of logic to choose the best error message for the user
35
35
  # according to the error class
36
36
  self.body{|ex|
37
- ex = ex.root_cause if ex.is_a?(Finitio::TypeError)
38
- { code: ex.class.name, description: ex.message }.to_json
37
+ body_for(ex).to_json
39
38
  }
40
39
 
40
+ def body_for(ex)
41
+ ex = ex.root_cause if ex.is_a?(Finitio::TypeError)
42
+ body = { code: ex.class.name, description: ex.message }
43
+ return body unless ex.is_a?(Startback::Errors::Error)
44
+ return body unless ex.has_causes?
45
+
46
+ body[:causes] = ex.causes
47
+ .filter{|cause|
48
+ cause.is_a?(Startback::Errors::Error)
49
+ }
50
+ .map{|cause|
51
+ body_for(cause)
52
+ }
53
+ body
54
+ end
55
+
41
56
  end # class Shield
42
57
  end # module Web
43
58
  end # module Startback
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: startback
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.10.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bernard Lambeau
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-22 00:00:00.000000000 Z
11
+ date: 2021-12-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec