-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Decorate errors automatically #27
Comments
I wonder whether this could be implemented in the form of response transformers, e.g. class Pragma::Transformer::CastSymbol < Pragma::Transformer::Base
def call(options)
return unless options['result.response'].is_a?(Symbol)
response_klass = "Pragma::Operation::Response::#{options['result.response'].to_s.camelize}"
options['result.response'] = response_klass.constantize
end
end
class Pragma::Transformer::Instantiate < Pragma::Transformer::Base
def call(options)
return unless options['result.response'] < Pragma::Operation::Response::Base
options['result.response'] = options['result.response'].new
end
end
class Pragma::Transformer::DecorateErrors < Pragma::Transformer::Base
def call(options)
return unless options['result.response'].entity.is_a?(Pragma::Error)
options['result.response'].decorate_with(Pragma::Decorator::Error)
end
end
Pragma::Operation::Base.transformers << Pragma::Transformer::CastSymbol
Pragma::Operation::Base.transformers << Pragma::Transformer::Instantiate
Pragma::Operation::Base.transformers << Pragma::Transformer::DecorateErrors Then we could do options['result.response'] = :not_found and get the response instantiated and decorated. I imagine this would be its own gem. In any case, it only makes sense if it would also be used in other places. My other concern is that this could very easily be abused to add steps to an operation without having to call |
Related to pragmarb/pragma-operation#2.
This pattern is very annoying:
There is no reason for that
decorate_with
to exist, it's just boilerplate.If
result.response
is a Pragma error response and it's not decorated, we should decorate it withPragma::Decorator::Error
automatically.We either do it in
pragma-operation
or decorate the base operation here, e.g.The problem with this is it cannot be overridden since it's not a step, and there is no way to ensure a step is actually run at the end of the operation.
The text was updated successfully, but these errors were encountered: