aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeorge Claghorn <george.claghorn@gmail.com>2018-08-10 18:35:49 -0400
committerGeorge Claghorn <george.claghorn@gmail.com>2018-08-10 18:35:49 -0400
commit18425b837149bc0d50f8d5349e1091a623762d6b (patch)
tree8720a2a396a3eacf825374fa6be109eebded53bf
parent5f9f39eb9c99475706a322e368274a48dd15a1ff (diff)
downloadrails-18425b837149bc0d50f8d5349e1091a623762d6b.tar.gz
rails-18425b837149bc0d50f8d5349e1091a623762d6b.tar.bz2
rails-18425b837149bc0d50f8d5349e1091a623762d6b.zip
Add a generic base class for Active Storage exceptions
Closes #33292. [Andrei Makarov & George Claghorn]
-rw-r--r--activestorage/CHANGELOG.md7
-rw-r--r--activestorage/lib/active_storage/errors.rb11
2 files changed, 14 insertions, 4 deletions
diff --git a/activestorage/CHANGELOG.md b/activestorage/CHANGELOG.md
index 0e9c2b5619..f6f195770c 100644
--- a/activestorage/CHANGELOG.md
+++ b/activestorage/CHANGELOG.md
@@ -1,3 +1,10 @@
+* Active Storage error classes like `ActiveStorage::IntegrityError` and
+ `ActiveStorage::UnrepresentableError` now inherit from `ActiveStorage::Error`
+ instead of `StandardError`. This permits rescuing `ActiveStorage::Error` to
+ handle all Active Storage errors.
+
+ *Andrei Makarov*, *George Claghorn*
+
* Uploaded files assigned to a record are persisted to storage when the record
is saved instead of immediately.
diff --git a/activestorage/lib/active_storage/errors.rb b/activestorage/lib/active_storage/errors.rb
index bedcd080c4..0547b8e705 100644
--- a/activestorage/lib/active_storage/errors.rb
+++ b/activestorage/lib/active_storage/errors.rb
@@ -1,11 +1,14 @@
# frozen_string_literal: true
module ActiveStorage
- class InvariableError < StandardError; end
- class UnpreviewableError < StandardError; end
- class UnrepresentableError < StandardError; end
+ # Generic base class for all Active Storage exceptions.
+ class Error < StandardError; end
+
+ class InvariableError < Error; end
+ class UnpreviewableError < Error; end
+ class UnrepresentableError < Error; end
# Raised when uploaded or downloaded data does not match a precomputed checksum.
# Indicates that a network error or a software bug caused data corruption.
- class IntegrityError < StandardError; end
+ class IntegrityError < Error; end
end