From 80ab6650546ebe2a2bec33b0051881fb845dc69b Mon Sep 17 00:00:00 2001 From: soh_cah_toa Date: Wed, 5 Jun 2013 16:56:05 -0400 Subject: [PATCH] Added new InvalidParamError class for handling bad named parameters. Previously, InvalidJsonError was being used mistakenly for this which is misleading considering no JSON was involved. --- extensions/dns/rest/dns.rb | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/extensions/dns/rest/dns.rb b/extensions/dns/rest/dns.rb index d603df58e..5661e7bf7 100644 --- a/extensions/dns/rest/dns.rb +++ b/extensions/dns/rest/dns.rb @@ -46,12 +46,12 @@ module Dns id = params[:id] unless BeEF::Filters.alphanums_only?(id) - raise InvalidJsonError, 'Invalid id passed to endpoint /api/dns/rule/:id' + raise InvalidParamError, 'Invalid "id" parameter passed to endpoint /api/dns/rule/:id' end result = BeEF::Extension::Dns::Server.instance.get_rule(id) result.to_json - rescue InvalidJsonError => e + rescue InvalidParamError => e print_error e.message halt 400 rescue StandardError => e @@ -123,11 +123,11 @@ module Dns id = params[:id] unless BeEF::Filters.alphanums_only?(id) - raise InvalidJsonError, 'Invalid id passed to endpoint /api/dns/rule/:id' + raise InvalidParamError, 'Invalid "id" parameter passed to endpoint /api/dns/rule/:id' end BeEF::Extension::Dns::Server.instance.remove_rule(id) - rescue InvalidJsonError => e + rescue InvalidParamError => e print_error e.message halt 400 rescue StandardError => e @@ -223,6 +223,17 @@ module Dns end + # Raised when an invalid named parameter is passed to an /api/dns handler. + class InvalidParamError < StandardError + + DEFAULT_MESSAGE = 'Invalid parameter passed to /api/dns handler' + + def initialize(message = nil) + super(message || DEFAULT_MESSAGE) + end + + end + end end