standard_circuit 0.1.1 → 0.1.2
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 +4 -4
- data/CHANGELOG.md +8 -0
- data/lib/standard_circuit/controller_support.rb +21 -0
- data/lib/standard_circuit/error_taxonomies.rb +43 -0
- data/lib/standard_circuit/version.rb +1 -1
- data/lib/standard_circuit.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e92eb79ddb1cfc0f2e9221aa62f45d7c304df0dfea22c114eb31a78c071b6c3c
|
|
4
|
+
data.tar.gz: 0aac1e3c093805ea2825cfb434840d83842999cb757cdcca896466c86a6abbff
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9e5ac3bb1d7352c6300fa70530602910dd3a45539e1cfad5d45b8ac702a223a22961cdaef377daf7c968ad7bbb5db54814c70a40b1a054a41df88c15fc5908c2
|
|
7
|
+
data.tar.gz: e8f4b265dd59f67442b52fafdb4db15923236df241b4296adc80bb6576654a888cdc564a5c2aa36e9ad291f5720f0c7fae7a274edcce046bb6995b6fbcb04dc7
|
data/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.
|
|
|
4
4
|
|
|
5
5
|
## [Unreleased]
|
|
6
6
|
|
|
7
|
+
## [0.1.2] - 2026-04-27
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
- `StandardCircuit::ErrorTaxonomies::{Stripe,Smtp,Aws,Faraday}.tracked` — pre-combined `NetworkErrors.defaults + AdapterErrors::X.server_errors` arrays. Saves consumers from typing the same line for every circuit they register and gives a single place to evolve what counts as a "server-side outage" per integration. `caller_errors` (validation/auth/etc.) stay on `AdapterErrors::*` because the right `skipped_errors` set is usually app-specific.
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
- `ControllerSupport.circuit_open_fallback` now appends a fresh `rescue_from Stoplight::Error::RedLight` handler each time it's called (deduplicating any prior RedLight handler on the class first, so repeated calls don't accumulate). Rails matches `rescue_handlers` last-declared-first, so a `rescue_from StandardError` catch-all declared *after* `include StandardCircuit::ControllerSupport` previously shadowed the gem's RedLight handler. As long as `circuit_open_fallback` is called after any catch-all rescues in your controller, RedLight now keeps routing to `handle_circuit_open` reliably.
|
|
14
|
+
|
|
7
15
|
## [0.1.1] - 2026-04-27
|
|
8
16
|
|
|
9
17
|
### Fixed
|
|
@@ -14,6 +14,14 @@ module StandardCircuit
|
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
class_methods do
|
|
17
|
+
# Rails iterates `rescue_handlers` from last-declared to first to find a
|
|
18
|
+
# match, so a `rescue_from StandardError` declared *after* `include
|
|
19
|
+
# StandardCircuit::ControllerSupport` shadows the gem's `RedLight` handler
|
|
20
|
+
# registered in `included`. Re-appending the handler here makes the DSL
|
|
21
|
+
# call effectively bump it to the end of the list — so as long as
|
|
22
|
+
# `circuit_open_fallback` is the last thing in your controller (or at
|
|
23
|
+
# least after any `rescue_from StandardError`-style catch-alls),
|
|
24
|
+
# `Stoplight::Error::RedLight` keeps routing to `handle_circuit_open`.
|
|
17
25
|
def circuit_open_fallback(status: :service_unavailable, html: nil, json: nil, stream: nil)
|
|
18
26
|
self._circuit_open_fallback = {
|
|
19
27
|
status: status,
|
|
@@ -21,6 +29,19 @@ module StandardCircuit
|
|
|
21
29
|
json: json,
|
|
22
30
|
stream: stream
|
|
23
31
|
}
|
|
32
|
+
|
|
33
|
+
# Drop existing RedLight handlers on this class before re-appending so
|
|
34
|
+
# repeated DSL calls (or sub-controllers calling the DSL after a base
|
|
35
|
+
# controller did) don't accumulate duplicate entries in
|
|
36
|
+
# `rescue_handlers`. Use the writer (not `reject!`) to avoid mutating
|
|
37
|
+
# the array a parent class might still share via `class_attribute`.
|
|
38
|
+
# Each entry's first element is a class-name string
|
|
39
|
+
# ("Stoplight::Error::RedLight"), not the constant itself.
|
|
40
|
+
self.rescue_handlers = rescue_handlers.reject { |handler| handler.first == "Stoplight::Error::RedLight" }
|
|
41
|
+
|
|
42
|
+
rescue_from Stoplight::Error::RedLight do |error|
|
|
43
|
+
handle_circuit_open(error)
|
|
44
|
+
end
|
|
24
45
|
end
|
|
25
46
|
end
|
|
26
47
|
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
module StandardCircuit
|
|
2
|
+
# Pre-combined `tracked_errors` sets per adapter — saves consumers from
|
|
3
|
+
# typing the same `NetworkErrors.defaults + AdapterErrors::X.server_errors`
|
|
4
|
+
# line for every circuit they register, and gives a single place to evolve
|
|
5
|
+
# what counts as a "server-side outage" for each integration.
|
|
6
|
+
#
|
|
7
|
+
# Each adapter's `tracked` returns a fresh array, so callers can safely
|
|
8
|
+
# `+` additional app-specific error classes without mutating shared state.
|
|
9
|
+
#
|
|
10
|
+
# Example:
|
|
11
|
+
# c.register(:stripe,
|
|
12
|
+
# tracked_errors: StandardCircuit::ErrorTaxonomies::Stripe.tracked,
|
|
13
|
+
# skipped_errors: StandardCircuit::AdapterErrors::Stripe.caller_errors)
|
|
14
|
+
#
|
|
15
|
+
# Adapter-specific `caller_errors` (validation/auth/etc.) stay on
|
|
16
|
+
# `AdapterErrors::*` because the right `skipped_errors` set is usually
|
|
17
|
+
# app-specific and a shared taxonomy would over-skip.
|
|
18
|
+
module ErrorTaxonomies
|
|
19
|
+
module Stripe
|
|
20
|
+
def self.tracked
|
|
21
|
+
NetworkErrors.defaults + AdapterErrors::Stripe.server_errors
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
module Smtp
|
|
26
|
+
def self.tracked
|
|
27
|
+
NetworkErrors.defaults + AdapterErrors::Smtp.server_errors
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
module Aws
|
|
32
|
+
def self.tracked
|
|
33
|
+
NetworkErrors.defaults + AdapterErrors::Aws.server_errors
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
module Faraday
|
|
38
|
+
def self.tracked
|
|
39
|
+
NetworkErrors.defaults + AdapterErrors::Faraday.server_errors
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
data/lib/standard_circuit.rb
CHANGED
|
@@ -8,6 +8,7 @@ require "standard_circuit/adapter_errors/stripe"
|
|
|
8
8
|
require "standard_circuit/adapter_errors/aws"
|
|
9
9
|
require "standard_circuit/adapter_errors/faraday"
|
|
10
10
|
require "standard_circuit/adapter_errors/smtp"
|
|
11
|
+
require "standard_circuit/error_taxonomies"
|
|
11
12
|
require "standard_circuit/notifiers/logger"
|
|
12
13
|
require "standard_circuit/notifiers/sentry"
|
|
13
14
|
require "standard_circuit/notifiers/metrics"
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: standard_circuit
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jaryl Sim
|
|
@@ -87,6 +87,7 @@ files:
|
|
|
87
87
|
- lib/standard_circuit/adapter_errors/stripe.rb
|
|
88
88
|
- lib/standard_circuit/config.rb
|
|
89
89
|
- lib/standard_circuit/controller_support.rb
|
|
90
|
+
- lib/standard_circuit/error_taxonomies.rb
|
|
90
91
|
- lib/standard_circuit/health.rb
|
|
91
92
|
- lib/standard_circuit/health_controller.rb
|
|
92
93
|
- lib/standard_circuit/mailer/circuit_open_error.rb
|