yes-command-api 2.6.0 → 2.6.1

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
  SHA256:
3
- metadata.gz: 6356c353ff44a1b4aabc48adea30a3b12b483c301a685632af7018184392dc4a
4
- data.tar.gz: 298dc25b06f8b7c8883ef9284319c30c328b492efc5f1b1888034521797f23e1
3
+ metadata.gz: e07253b3712b444afdcf4d1e13845dddf21165c8472c5dc613a15e2725675fb5
4
+ data.tar.gz: b793812590fd7dedc304374d072f2861239a0da9cbfee0a3105589068452a349
5
5
  SHA512:
6
- metadata.gz: e8e2936d136176613de46dcf987b7b9dc9981618fd3633ae3d038ef846d1a26d52dda80cf1fbd904fbea73bb276749122d73da87b5ef6e63c5731438ca9e3c37
7
- data.tar.gz: 515024c90a326b111ef6cfb050c1b2f89e41e027d73d5d997cdb7522536f373f1729bd5059d16e1e9e91a5499445ce992bdb7397e5ad64bba0f4c920c948f2a0
6
+ metadata.gz: 2e8c596d713bbe6241387dec33c6d036883fa1a925bcec9778d1389621acb82a183b1171449db378a4ce5f14cc4982baf3ba40fbab1a614dfaf59fb9bd501ce7
7
+ data.tar.gz: 48dc3b4d2e32680ac2c768560dfa643657ea4f76178c076f4aa7bebd26cf76771063bade7c0cfe7a7ed17555073eba487bf77a1adfd035809dd52319a0555c4a
@@ -10,6 +10,7 @@ module Yes
10
10
  # If no auth adapter is configured, authentication will raise an error.
11
11
  class CommandsController < ActionController::API
12
12
  MAX_INLINE_COMMANDS_PER_REQ = 10
13
+ RETRY_AFTER_SECONDS = 1
13
14
 
14
15
  include Yes::Core::OpenTelemetry::Trackable
15
16
 
@@ -17,6 +18,12 @@ module Yes
17
18
  before_action :set_channel
18
19
 
19
20
  rescue_from(StandardError, with: :handle_unexpected_error)
21
+ # Declared after StandardError: Rails checks the last declared handler first.
22
+ rescue_from(
23
+ Cerbos::Error::Unavailable,
24
+ Cerbos::Error::DeadlineExceeded,
25
+ with: :authorization_service_unavailable_response
26
+ )
20
27
  rescue_from(Yes::Core::AuthenticationError, with: :auth_error_response)
21
28
 
22
29
  rescue_from(
@@ -189,6 +196,20 @@ module Yes
189
196
  span_kind: :client
190
197
  )
191
198
 
199
+ # Authorization of the whole batch precedes any execution, so nothing ran and the client
200
+ # can safely retry the request.
201
+ def authorization_service_unavailable_response(error)
202
+ self.class.current_span&.status = OpenTelemetry::Trace::Status.error(error.message)
203
+ self.class.current_span&.record_exception(error)
204
+ Rails.error.report(error, handled: true, severity: :error)
205
+
206
+ response.set_header('Retry-After', RETRY_AFTER_SECONDS.to_s)
207
+ render(
208
+ json: { title: 'Service Unavailable', detail: 'Authorization service unavailable' }.to_json,
209
+ status: :service_unavailable
210
+ )
211
+ end
212
+
192
213
  def handle_unexpected_error(error)
193
214
  self.class.current_span&.status = OpenTelemetry::Trace::Status.error(error.message)
194
215
  self.class.current_span&.record_exception(error)
@@ -3,7 +3,7 @@
3
3
  module Yes
4
4
  module Command
5
5
  module Api
6
- VERSION = '2.6.0'
6
+ VERSION = '2.6.1'
7
7
  end
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yes-command-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.6.0
4
+ version: 2.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nico Ritsche