Module: JsClientBridge::Responses::Exception
- Included in:
- JsClientBridge::Responses
- Defined in:
- lib/js-client-bridge/responses/exception.rb
Instance Method Summary collapse
Instance Method Details
#respond_with_exception(*args) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/js-client-bridge/responses/exception.rb', line 7 def respond_with_exception(*args) raise ArgumentError.new("respond_with_exception requires an exception as it's first parameter") if args.blank? || !args.first.is_a?(StandardError) exception = args.shift = args.last.is_a?(Hash) ? args.pop : {} # Ensure we have our required fields raise ArgumentError.new("respond_with_exception requires the request_uri option") unless .include?(:request_uri) # Set some defaults [:parameters] ||= {} # Generate our response hash and add the exceptions parameter response, formatting = respond_with('exception', []) response[:exceptions] = [{ :name => exception.class, :short_name => exception.class.to_s.split('::').last, :message => CGI.escape(exception.), :backtrace => exception.backtrace }] format_response(response, formatting) end |
#respond_with_exceptions(*args) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/js-client-bridge/responses/exception.rb', line 31 def respond_with_exceptions(*args) raise ArgumentError.new("respond_with_exception requires an array of exceptions as it's first parameter") if args.blank? || !args.first.is_a?(Array) exceptions = args.shift = args.last.is_a?(Hash) ? args.pop : {} # Ensure we have our required fields raise ArgumentError.new("respond_with_exception requires the request_uri option") unless .include?(:request_uri) # Set some defaults [:parameters] ||= {} # Generate our response hash and add the exceptions parameter response, formatting = respond_with('exception', []) response[:exceptions] = exceptions.map do |exception| { :name => exception.class, :short_name => exception.class.to_s.split('::').last, :message => CGI.escape(exception.), :backtrace => exception.backtrace } end format_response(response, formatting) end |