safrano 0.6.5 → 0.6.6

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: b71032a7ee1e048867f3b54f57d920ba772a44f29a3419a598d2206d50e949c7
4
- data.tar.gz: d203df34eda2c7aad9385a84e866d273f1a1f37ba981ffdcc8956de9dad35633
3
+ metadata.gz: '0108c5a48b2cbd994534ba6732f760dec8f8e8becac690d91b3f1960dd6f7836'
4
+ data.tar.gz: c9b8c3c8a7f7ac3d7db5a12133ba3fdcd4815df5b3dab1d35bfaf449518f8d2c
5
5
  SHA512:
6
- metadata.gz: d5cb1583e62f42f9007368204d24f101273049c05e75723dbcd7796732d83e1ac29a1515df0a876a2002c212b0da8204c498070104688fd4b493092072e13dee
7
- data.tar.gz: 96aa136d330148331b98943807c83b42e466aa7357c8b360b3f5a66843b9472df41015309b2bef19d993bdabf5f4d1d41e983e7082a1f06d34015370bc87a034
6
+ metadata.gz: '0068c08576a0d8df023d6990ad691ce73b1d3abd6f3a9cd095b7ae2f9358dc7d33d7ed5d0fdde2503a2829ebeb11ab126961a39d34d12370befbb5814904f7b1'
7
+ data.tar.gz: cbf6fbdd2d1f4a24ba58b14490dfcfc87e1ffc333ab52b0e334b06742679543a794359f16093f56cc78e7a754724ee3e24f70ec7b7277d3ce6d04af3d1f9ae5f
@@ -81,9 +81,9 @@ module Safrano
81
81
  end
82
82
 
83
83
  # needed for ComplexType result
84
- def to_odata_json(_req)
84
+ def to_odata_json(req)
85
85
  t = self.class.klassmod.output_template
86
- innerh = _req.service.get_entity_odata_h(entity: @value, template: t)
86
+ innerh = req.service.get_entity_odata_h(entity: @value, template: t)
87
87
  innerj = innerh.to_json
88
88
 
89
89
  "#{DJ_OPEN}#{innerj}#{DJ_CLOSE}"
data/lib/odata/error.rb CHANGED
@@ -48,6 +48,13 @@ module Safrano
48
48
  end
49
49
  end
50
50
 
51
+ # used in function import error handling. cf. func import / do_execute_func
52
+ def self.with_error(result)
53
+ if result.respond_to?(:error) && (err = result.error)
54
+ yield err
55
+ end
56
+ end
57
+
51
58
  # base module for HTTP errors, when used as a Error Class
52
59
  module ErrorClass
53
60
  include ::Safrano::Contract::Invalid
@@ -94,10 +101,20 @@ module Safrano
94
101
  # generic http 500 server err
95
102
  class ServerError
96
103
  extend ErrorClass
104
+ include ErrorInstance
97
105
  HTTP_CODE = 500
98
106
  @msg = 'Server error'
99
107
  end
100
108
 
109
+ class ServiceOperationError
110
+ extend ErrorClass
111
+ include ErrorInstance
112
+ HTTP_CODE = 500
113
+ def initialize(msg:, sopname: nil)
114
+ @msg = "Error in service operation #{sopname}: #{msg}"
115
+ end
116
+ end
117
+
101
118
  # for outputing Sequel exceptions that we could not prevent
102
119
  class SequelExceptionError < ServerError
103
120
  include ErrorInstance
@@ -18,6 +18,7 @@ module Safrano
18
18
  def initialize(name)
19
19
  @name = name
20
20
  @http_method = 'GET'
21
+ @use_contract = false
21
22
  end
22
23
 
23
24
  def allowed_transitions
@@ -52,6 +53,10 @@ module Safrano
52
53
  end
53
54
  alias auto_query_params auto_query_parameters
54
55
 
56
+ def use_contract
57
+ @use_contract = true
58
+ end
59
+
55
60
  def return(klassmod, &proc)
56
61
  raise('Please provide a code block') unless block_given?
57
62
 
@@ -159,6 +164,18 @@ module Safrano
159
164
  def do_execute_func(req)
160
165
  with_transition_validated(req) do
161
166
  result = @proc.call(**@funcparams)
167
+
168
+ # (application-)error handling
169
+ # the result is an Error object or class
170
+
171
+ # Note: Sequel::Error exceptions are already
172
+ # handled on rack app level (cf. the call methode )
173
+ Safrano::with_error(result) do |error|
174
+ @error = error
175
+ return [nil, :error, @error] # this is return from do_execute_func !
176
+ end
177
+
178
+ # non error case
162
179
  [@returning.do_execute_func_result(result, req, @auto_query_params), :run]
163
180
  end
164
181
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Safrano
4
- VERSION = '0.6.5'
4
+ VERSION = '0.6.6'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: safrano
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.5
4
+ version: 0.6.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - oz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-12-28 00:00:00.000000000 Z
11
+ date: 2023-01-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack