Index: src/wp-includes/comment.php
===================================================================
--- src/wp-includes/comment.php	(revision 37478)
+++ src/wp-includes/comment.php	(working copy)
@@ -38,7 +38,6 @@
  */
 function check_comment($author, $email, $url, $comment, $user_ip, $user_agent, $comment_type) {
 	global $wpdb;
-
 	// If manual moderation is enabled, skip all checks and return false.
 	if ( 1 == get_option('comment_moderation') )
 		return false;
@@ -582,13 +581,15 @@
  * Validates whether this comment is allowed to be made.
  *
  * @since 2.0.0
+ * @since trunk Define $return_error if function returns an error or uses wp_die()
  *
  * @global wpdb $wpdb WordPress database abstraction object.
  *
- * @param array $commentdata Contains information on the comment
+ * @param array   $commentdata Contains information on the comment
+ * @param boolean $return_error Wheter to return an error or to use wp_die(). Default: false
  * @return int|string Signifies the approval status (0|1|'spam')
  */
-function wp_allow_comment( $commentdata ) {
+function wp_allow_comment( $commentdata, $return_error = false ) {
 	global $wpdb;
 
 	// Simple duplicate check
@@ -633,10 +634,14 @@
 		 * @param array $commentdata Comment data.
 		 */
 		do_action( 'comment_duplicate_trigger', $commentdata );
-		if ( defined( 'DOING_AJAX' ) ) {
-			die( __('Duplicate comment detected; it looks as though you&#8217;ve already said that!') );
+		if( $return_error ) {
+			return new WP_Error( 'duplicate_comment', __( 'Duplicate comment detected; it looks as though you&#8217;ve already said that!' ), 409 );
+		} else {
+			if ( defined( 'DOING_AJAX' ) ) {
+				die( __('Duplicate comment detected; it looks as though you&#8217;ve already said that!') );
+			}
+			wp_die( __( 'Duplicate comment detected; it looks as though you&#8217;ve already said that!' ), 409 );
 		}
-		wp_die( __( 'Duplicate comment detected; it looks as though you&#8217;ve already said that!' ), 409 );
 	}
 
 	/**
@@ -646,17 +651,36 @@
 	 *
 	 * @since 2.3.0
 	 *
-	 * @param string $comment_author_IP    Comment author's IP address.
-	 * @param string $comment_author_email Comment author's email.
-	 * @param string $comment_date_gmt     GMT date the comment was posted.
+	 * @param string  $comment_author_IP    Comment author's IP address.
+	 * @param string  $comment_author_email Comment author's email.
+	 * @param string  $comment_date_gmt     GMT date the comment was posted.
+	 * @param boolean $return_error         If the expected behavior is to die if a comment is detected to be part of a flood
 	 */
 	do_action(
 		'check_comment_flood',
 		$commentdata['comment_author_IP'],
 		$commentdata['comment_author_email'],
-		$commentdata['comment_date_gmt']
+		$commentdata['comment_date_gmt'],
+		$return_error
 	);
 
+
+	/**
+	 * Filters if a comment is part of a comment flood.
+	 *
+	 * @since trunk
+	 *
+	 * @param boolean $is_flood             If a comment is flagged as being part of a flood.
+	 * @param string  $comment_author_IP    Comment author's IP address.
+	 * @param string  $comment_author_email Comment author's email.
+	 * @param string  $comment_date_gmt     GMT date the comment was posted.
+	 * @param boolean $return_error         Indicating if wp_die() is supposed to be executed in case of a flood
+	 */
+	$is_flood = apply_filters( 'is_comment_flood', false, $commentdata['comment_author_IP'], $commentdata['comment_author_email'], $commentdata['comment_date_gmt'], $return_error );
+	if ( $is_flood && $return_error ) {
+		return new WP_Error( 'comment_flood', __( 'You are posting comments too quickly. Slow down.' ), 429 );
+	}
+
 	if ( ! empty( $commentdata['user_id'] ) ) {
 		$user = get_userdata( $commentdata['user_id'] );
 		$post_author = $wpdb->get_var( $wpdb->prepare(
@@ -708,7 +732,32 @@
 	return $approved;
 }
 
+
 /**
+ * Filters whether comment flooding is occurring.
+ *
+ * @since trunk
+ *
+ * @param boolean  $is_flood If the current comment is part of a flood
+ * @param string   $ip Comment IP.
+ * @param string   $email Comment author email address.
+ * @param string   $date MySQL time string.
+ * @param boolean  $return_error Wether to return a WP_Error on flood or use wp_die()
+ *
+ * @return boolean $is_flood If the current comment is part of a flood
+ */
+function check_comment_flood_db_filter( $is_flood, $ip, $email, $date, $return_error = false ) {
+	if ( $is_flood ) {
+		return $is_flood;
+	}
+	$is_flood = check_comment_flood_db( $ip, $email, $date, $return_error );
+	if ( true !== $is_flood ) {
+		return false;
+	}
+	return true;
+}
+
+/**
  * Check whether comment flooding is occurring.
  *
  * Won't run, if current user can manage options, so to not block
@@ -715,14 +764,19 @@
  * administrators.
  *
  * @since 2.3.0
+ * @since trunk $return_error indicating if a WP_Error object should be returned instead of using wp_die()
  *
  * @global wpdb $wpdb WordPress database abstraction object.
  *
- * @param string $ip Comment IP.
- * @param string $email Comment author email address.
- * @param string $date MySQL time string.
+ * @param string  $ip Comment IP.
+ * @param string  $email Comment author email address.
+ * @param string  $date MySQL time string.
+ * @param boolean $return_error Wether to return a WP_Error on flood or use wp_die()
+ *
+ * @return mixed  if $return_error is true it returns a boolean indicating the flood. Otherwise nothing will be returned.
  */
-function check_comment_flood_db( $ip, $email, $date ) {
+function check_comment_flood_db( $ip, $email, $date, $return_error = false ) {
+
 	global $wpdb;
 	// don't throttle admins or moderators
 	if ( current_user_can( 'manage_options' ) || current_user_can( 'moderate_comments' ) ) {
@@ -768,13 +822,19 @@
 			 * @param int $time_newcomment  Timestamp of when the new comment was posted.
 			 */
 			do_action( 'comment_flood_trigger', $time_lastcomment, $time_newcomment );
-
-			if ( defined('DOING_AJAX') )
-				die( __('You are posting comments too quickly. Slow down.') );
-
-			wp_die( __( 'You are posting comments too quickly. Slow down.' ), 429 );
+			if( $return_error ) {
+				return $flood_die;
+			} else {
+				if ( defined('DOING_AJAX') )
+					die( __('You are posting comments too quickly. Slow down.') );
+				wp_die( __( 'You are posting comments too quickly. Slow down.' ), 429 );
+			}
 		}
 	}
+
+	if( $return_error ) {
+		return false;
+	}
 }
 
 /**
@@ -1711,6 +1771,7 @@
  *
  * @since 1.5.0
  * @since 4.3.0 'comment_agent' and 'comment_author_IP' can be set via `$commentdata`.
+ * @since trunk $return_error boolean to be able to return errors instead of using wp_die()
  *
  * @see wp_insert_comment()
  * @global wpdb $wpdb WordPress database abstraction object.
@@ -1734,9 +1795,10 @@
  *     @type string $comment_author_IP    Comment author IP address in IPv4 format. Default is the value of
  *                                        'REMOTE_ADDR' in the `$_SERVER` superglobal sent in the original request.
  * }
+ * @param boolean   $return_error         Return a WP_Error instead of using wp_die(). Default: false
  * @return int|false The ID of the comment on success, false on failure.
  */
-function wp_new_comment( $commentdata ) {
+function wp_new_comment( $commentdata, $return_error = false ) {
 	global $wpdb;
 
 	if ( isset( $commentdata['user_ID'] ) ) {
@@ -1785,7 +1847,10 @@
 
 	$commentdata = wp_filter_comment($commentdata);
 
-	$commentdata['comment_approved'] = wp_allow_comment($commentdata);
+	$commentdata['comment_approved'] = wp_allow_comment( $commentdata, $return_error );
+	if ( is_wp_error( $commentdata['comment_approved'] ) ) {
+		return $commentdata['comment_approved'];
+	}
 
 	$comment_ID = wp_insert_comment($commentdata);
 	if ( ! $comment_ID ) {
@@ -1799,7 +1864,10 @@
 
 		$commentdata = wp_filter_comment( $commentdata );
 
-		$commentdata['comment_approved'] = wp_allow_comment( $commentdata );
+		$commentdata['comment_approved'] = wp_allow_comment( $commentdata, $return_error );
+		if ( is_wp_error( $commentdata['comment_approved'] ) ) {
+			return $commentdata['comment_approved'];
+		}
 
 		$comment_ID = wp_insert_comment( $commentdata );
 		if ( ! $comment_ID ) {
@@ -2916,7 +2984,12 @@
 		'user_ID'
 	);
 
-	$comment_id = wp_new_comment( wp_slash( $commentdata ) );
+	$comment_id = wp_new_comment( wp_slash( $commentdata ), true );
+
+	if ( is_wp_error( $comment_id ) ) {
+		return $comment_id;
+	}
+
 	if ( ! $comment_id ) {
 		return new WP_Error( 'comment_save_error', __( '<strong>ERROR</strong>: The comment could not be saved. Please try again later.' ), 500 );
 	}
Index: src/wp-includes/default-filters.php
===================================================================
--- src/wp-includes/default-filters.php	(revision 37478)
+++ src/wp-includes/default-filters.php	(working copy)
@@ -190,7 +190,7 @@
 add_filter( 'teeny_mce_before_init',    '_mce_set_direction'                  );
 add_filter( 'pre_kses',                 'wp_pre_kses_less_than'               );
 add_filter( 'sanitize_title',           'sanitize_title_with_dashes',   10, 3 );
-add_action( 'check_comment_flood',      'check_comment_flood_db',       10, 3 );
+add_filter( 'is_comment_flood',         'check_comment_flood_db_filter',10, 5 );
 add_filter( 'comment_flood_filter',     'wp_throttle_comment_flood',    10, 3 );
 add_filter( 'pre_comment_content',      'wp_rel_nofollow',              15    );
 add_filter( 'comment_email',            'antispambot'                         );
Index: tests/phpunit/tests/comment-submission.php
===================================================================
--- tests/phpunit/tests/comment-submission.php	(revision 37478)
+++ tests/phpunit/tests/comment-submission.php	(working copy)
@@ -714,4 +714,65 @@
 		return $commentdata;
 	}
 
-}
+
+
+	public function test_submitting_duplicate_comments() {
+		$post = self::factory()->post->create_and_get( array(
+			'post_status' => 'publish',
+		) );
+		$data = array(
+			'comment_post_ID'       => $post->ID,
+			'comment'               => 'Did I say that?',
+			'author'                => 'Repeat myself',
+			'email'                 => 'mail@example.com',
+		);
+		$first_comment = wp_handle_comment_submission( $data );		
+		$second_comment = wp_handle_comment_submission( $data );
+		$this->assertWPError( $second_comment );
+		$this->assertSame( 'duplicate_comment', $second_comment->get_error_code() );
+	}
+
+	public function test_comments_flood() {
+		$post = self::factory()->post->create_and_get( array(
+			'post_status' => 'publish',
+		) );
+		$data = array(
+			'comment_post_ID'       => $post->ID,
+			'comment'               => 'Did I say that?',
+			'author'                => 'Repeat myself',
+			'email'                 => 'mail@example.com',
+		);
+		$first_comment = wp_handle_comment_submission( $data );
+
+		$data['comment'] = 'Wow! I am quick!';	
+		$second_comment = wp_handle_comment_submission( $data );
+
+		$this->assertWPError( $second_comment );
+		$this->assertSame( 'comment_flood', $second_comment->get_error_code() );
+	}
+
+	public function test_comments_flood_user_is_admin() {
+		$user = self::factory()->user->create_and_get( array(
+			'role' => 'administrator',
+		) );
+		wp_set_current_user( $user->ID );
+
+		$post = self::factory()->post->create_and_get( array(
+			'post_status' => 'publish',
+		) );
+		$data = array(
+			'comment_post_ID'       => $post->ID,
+			'comment'               => 'Did I say that?',
+			'author'                => 'Repeat myself',
+			'email'                 => 'mail@example.com',
+		);
+		$first_comment = wp_handle_comment_submission( $data );
+		
+		$data['comment'] = 'Wow! I am quick!';	
+		$second_comment = wp_handle_comment_submission( $data );
+
+		$this->assertNotWPError( $second_comment );
+		$this->assertEquals( $post->ID, $second_comment->comment_post_ID );
+	}
+
+}
\ No newline at end of file
