Skip to content

Commit

Permalink
Make failed sub operations result in error 500 when called via contro…
Browse files Browse the repository at this point in the history
…ller
  • Loading branch information
sudoremo committed Jul 25, 2023
1 parent 5b82ec3 commit 5e574c5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
# Changelog

## 1.4.5 (2023-07-25)

* Make sure that `RailsOps::Exceptions::SubOpValidationFailed` always results in
an Error 500 when handled by a Rails controller.

Internal reference: `#114719`.

## 1.4.5 (2023-07-10)

* Fix bug introduced in previous release 1.4.4.

Internal reference: `#114719`.

## 1.4.4 (2023-07-10)

* Adapt method `sub_op` to catch `<op-class>.validation_errors` and re-throw
them as `RailsOps::Exceptions::SubOpValidationFailed`.

Internal reference: `#114719`.

## 1.4.3 (2023-03-27)

* Extend the `operation` generator to accept additional flags to skip the
Expand Down
11 changes: 11 additions & 0 deletions lib/rails_ops/controller_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ module ControllerMixin
fail ActionController::BadRequest
end
end

# #114719: If 'rescue_validation_error_in_controller' is enabled, the
# exception 'SubOpValidationFailed' may have
# 'Schemacop::Exceptions::ValidationError' as a 'cause', which in turn
# causes ActiveSupport's 'Rescuable' to look for a rescue_from with the
# exception's 'cause', which would then result in a BadRequest. For this
# case, we add a separate rescue_from here so that 'SubOpValidationFailed'
# always results in an error 500 as it must be a programming error.
rescue_from RailsOps::Exceptions::SubOpValidationFailed do |e|
fail e
end
end

# Instantiates and returns a new operation with the given class. If no class
Expand Down

0 comments on commit 5e574c5

Please sign in to comment.