lib/angelo/responder.rb in angelo-0.1.0 vs lib/angelo/responder.rb in angelo-0.1.1

- old
+ new

@@ -57,18 +57,22 @@ @body = @response_handler.bind(@base).call || '' @base.after if @base.respond_to? :after else raise NotImplementedError end + rescue JSON::ParserError => jpe + handle_error jpe, :bad_request, false + rescue FormEncodingError => fee + handle_error fee, :bad_request, false rescue => e handle_error e end - def handle_error _error, report = true + def handle_error _error, type = :internal_server_error, report = true err_msg = error_message _error - Angelo.log @connection, @request, nil, :internal_server_error, err_msg.size - @connection.respond :internal_server_error, headers, err_msg + Angelo.log @connection, @request, nil, type, err_msg.size + @connection.respond type, headers, err_msg @connection.close if report error "#{_error.class} - #{_error.message}" ::STDERR.puts _error.backtrace end @@ -119,10 +123,10 @@ @body.to_json if respond_with? :json end Angelo.log @connection, @request, nil, :ok, @body.size @connection.respond :ok, headers, @body rescue => e - handle_error e, false + handle_error e, :internal_server_error, false end end end