Module: JsClientBridge::Responses::Exception
- Included in:
- JsClientBridge::Responses
- Defined in:
- lib/js-client-bridge/responses/exception.rb
Instance Method Summary collapse
- #render_exception(*args) ⇒ Object
- #render_exceptions(*args) ⇒ Object
- #respond_with_exception(*args) ⇒ Object
- #respond_with_exceptions(*args) ⇒ Object
Instance Method Details
#render_exception(*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 |
# File 'lib/js-client-bridge/responses/exception.rb', line 31 def render_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 |
#render_exceptions(*args) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/js-client-bridge/responses/exception.rb', line 82 def render_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 |
#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 }] response end |
#respond_with_exceptions(*args) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/js-client-bridge/responses/exception.rb', line 55 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 response end |