GithubHelp home page GithubHelp logo

Decorate errors automatically about pragma HOT 1 OPEN

pragmarb avatar pragmarb commented on July 21, 2024
Decorate errors automatically

from pragma.

Comments (1)

aldesantis avatar aldesantis commented on July 21, 2024

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 step. Perhaps we should only allow to manipulate the response and nothing else?

from pragma.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.