Project

General

Profile

Actions

Refactor #3627

open

Remove rescue blocks from actions and use error handler

Added by Marek Hulán over 10 years ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
-
Target version:
-
Difficulty:
Triaged:
Fixed in Releases:
Found in Releases:

Description

We use rescue blocks in actions like here

 post "/dns/" do
    fqdn  = params[:fqdn]
    value = params[:value]
    type  = params[:type]
    begin
      dns_setup({:fqdn => fqdn, :value => value, :type => type})
      @server.create
    rescue Proxy::DNS::Collision => e
      log_halt 409, e
    rescue Exception => e
      log_halt 400, e
    end
  end

Instead we should use error handler http://www.sinatrarb.com/intro.html#Error%20Handling at least for specific exceptions to be more DRY. We should add custom exceptions where needed.

No data to display

Actions

Also available in: Atom PDF