Skip to content

Commit

Permalink
Raise a helpful error when an operation doesn't set result.response
Browse files Browse the repository at this point in the history
  • Loading branch information
aldesantis committed Jul 5, 2018
1 parent 163b363 commit 2676ca9
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Added

- Started raising a `NoResponseError` if an operation doesn't return a `result.response` skill

## [2.2.0]

## Added
Expand Down
3 changes: 1 addition & 2 deletions lib/pragma/rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
require 'pragma/rails/version'
require 'pragma/rails/controller'
require 'pragma/rails/resource_controller'
require 'pragma/rails/errors'

require 'generators/pragma/resource_generator' if defined?(::Rails::Generators)

module Pragma
# Ruby on Rails integration for the Pragma architecture.
#
# @author Alessandro Desantis
module Rails
end
end
4 changes: 2 additions & 2 deletions lib/pragma/rails/controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ module Pragma
module Rails
# This mixin should be included in a Rails controller to provide integration with Pragma
# operations.
#
# @author Alessandro Desantis
module Controller
def self.included(klass)
klass.include InstanceMethods
Expand All @@ -28,6 +26,8 @@ def run(operation_klass)
'policy.context' => policy_context
)

fail NoResponseError unless result['result.response']

result['result.response'].headers.each_pair do |key, value|
response.headers[key] = value
end
Expand Down
14 changes: 14 additions & 0 deletions lib/pragma/rails/errors.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module Pragma
module Rails
class NoResponseError < StandardError
def initialize
super <<~MESSAGE
Your operation did not return a `result.response` skill, which might mean one of the following:
* The execution of the operation halted early (maybe one of your steps returned a falsey value?).
* You forgot to set a `result.response` skill in a custom operation.
MESSAGE
end
end
end
end
2 changes: 0 additions & 2 deletions lib/pragma/rails/resource_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
module Pragma
module Rails
# Exposes CRUD operations on a resource through a Rails controller.
#
# @author Alessandro Desantis
module ResourceController
def self.included(klass)
klass.include Controller
Expand Down

0 comments on commit 2676ca9

Please sign in to comment.