Skip to content
This repository was archived by the owner on Mar 18, 2019. It is now read-only.
This repository was archived by the owner on Mar 18, 2019. It is now read-only.

A way to store reusable error handling code #3

@lasseebert

Description

@lasseebert

Right now it is possible to reuse error handling code by using the pretty clumsy and undocumented self inside the kase block:

kase result do
  on(:ok) { |result| do_something_with(result) }
  common_error_handle(self)
end

with a error handling method like this:

def common_error_handle(matcher)
  matcher.on(:not_found) { render_not_found }
  matcher.on(:not_authorized) { render_not_authorized }
end

This will act as though the on methods from the common error handler was called inside the kase block.

This should be more explicit and also easier to swap on set of error handling with another.

Something like this:

common_error_handler = Kase::Handler.new do
  on(:not_found) { render_not_found }
  on(:not_authorized) { render_not_authorized }
end

kase result do |matcher|
  on(:ok) { |result| do_something_with(result) }
  apply(common_error_handler)
end

A Handler should store the on calls and maybe expose them for modification.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions