-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Labels
Description
Responding right now is very cumbersome in custom operations, e.g.
def respond!(options)
options['result.response'] = Pragma::Operation::Response::Ok.new(
entity: options['model'],
).decorate_with(Decorator::Instance)
endWe can simplify success and failure responses like this:
# Responds and returns true (for regular responses)
respond(options, :ok,
entity: options['model'] # optional (default is nil),
headers: {}, # optional
decorator: Decorator::Instance, # optional
)
# Responds and returns false (for errors)
respond!(options, :not_found,
entity: Pragma::Operation::Error.new(
error_type: :not_found,
error_message: 'The requested resource could not be found.',
),
headers: {},
decorator: Pragma::Decorator::Error,
)
# Shortcut for erroring (all arguments optional)
fail!(options, :not_found,
error_type: :not_found,
error_message: 'The requested resource could not be found.',
headers: {},
)Reactions are currently unavailable