Revision fcc0d38b
Added by Ohad Levy over 12 years ago
- ID fcc0d38bc89a9a3d6d372469bbc3a697e3b787f1
lib/dhcp_api.rb | ||
---|---|---|
end
|
||
@subnets = @server.subnets
|
||
rescue => e
|
||
log_halt 400, e.to_s
|
||
log_halt 400, e
|
||
end
|
||
|
||
helpers do
|
||
... | ... | |
erb :"dhcp/index"
|
||
end
|
||
rescue => e
|
||
log_halt 400, e.to_s
|
||
log_halt 400, e
|
||
end
|
||
end
|
||
|
||
... | ... | |
erb :"dhcp/show"
|
||
end
|
||
rescue => e
|
||
log_halt 400, e.to_s
|
||
log_halt 400, e
|
||
end
|
||
end
|
||
|
||
... | ... | |
content_type :json
|
||
({:ip => load_subnet.unused_ip}).to_json
|
||
rescue => e
|
||
log_halt 400, e.to_s
|
||
log_halt 400, e
|
||
end
|
||
end
|
||
|
||
... | ... | |
log_halt 404, "Record #{params[:network]}/#{params[:record]} not found" unless record
|
||
record.options.to_json
|
||
rescue => e
|
||
log_halt 400, e.to_s
|
||
log_halt 400, e
|
||
end
|
||
end
|
||
|
||
... | ... | |
options = params.reject{|k,v| k["network"]}
|
||
@server.addRecord(options)
|
||
rescue Proxy::DHCP::Collision => e
|
||
log_halt 409, e.to_s
|
||
log_halt 409, e
|
||
rescue Proxy::DHCP::AlreadyExists
|
||
# no need to do anything
|
||
rescue => e
|
||
log_halt 400, e.to_s
|
||
log_halt 400, e
|
||
end
|
||
end
|
||
|
||
... | ... | |
redirect "/dhcp/#{params[:network]}"
|
||
end
|
||
rescue Exception => e
|
||
log_halt 400, e.to_s
|
||
log_halt 400, e
|
||
end
|
||
end
|
||
end
|
lib/dns_api.rb | ||
---|---|---|
setup({:fqdn => fqdn, :value => value, :type => type})
|
||
@server.create
|
||
rescue Proxy::DNS::Collision => e
|
||
log_halt 409, e.to_s
|
||
log_halt 409, e
|
||
rescue Exception => e
|
||
log_halt 400, e.to_s
|
||
log_halt 400, e
|
||
end
|
||
end
|
||
|
||
... | ... | |
setup({:fqdn => fqdn, :value => value, :type => type})
|
||
@server.remove
|
||
rescue => e
|
||
log_halt 400, e.to_s
|
||
log_halt 400, e
|
||
end
|
||
end
|
||
end
|
lib/features_api.rb | ||
---|---|---|
erb :"features/index"
|
||
end
|
||
rescue => e
|
||
log_halt 400, e.to_s
|
||
log_halt 400, e
|
||
end
|
||
end
|
||
|
||
... | ... | |
begin
|
||
Proxy.version.to_json
|
||
rescue => e
|
||
log_halt 400, e.to_s
|
||
log_halt 400, e
|
||
end
|
||
end
|
||
|
lib/helpers.rb | ||
---|---|---|
# Accepts a html error code and a message, which is then returned to the caller after adding to the proxy log
|
||
# OR a block which is executed and its errors handled in a similar way.
|
||
# If no code is supplied when the block is declared then the html error used is 400.
|
||
def log_halt code=nil, message=nil
|
||
def log_halt code=nil, exception=nil
|
||
message = exception.is_a?(String) ? exception : exception.to_s
|
||
begin
|
||
if block_given?
|
||
return yield
|
||
... | ... | |
end
|
||
content_type :json if request.accept.include?("application/json")
|
||
logger.error message
|
||
logger.debug exception.backtrace.join("\n") if exception.is_a?(Exception)
|
||
halt code, message
|
||
end
|
||
end
|
Also available in: Unified diff
fixes #1149 - add backtrace to log failures