Index: src/wp-includes/functions.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/wp-includes/functions.php	(revision 44568)
+++ src/wp-includes/functions.php	(date 1547298831000)
@@ -2970,6 +2970,15 @@
 		 * @param callable $function Callback function name.
 		 */
 		$function = apply_filters( 'wp_die_ajax_handler', '_ajax_wp_die_handler' );
+	} else if ( wp_doing_rest()  ) {
+		/**
+		 * Filters the callback for killing WordPress execution for REST API requests.
+		 *
+		 * @since 5.1.0
+		 *
+		 * @param callable $function Callback function name.
+		 */
+		$function = apply_filters( 'wp_die_rest_handler', '_rest_wp_die_handler' );
 	} elseif ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST ) {
 		/**
 		 * Filters the callback for killing WordPress execution for XML-RPC requests.
@@ -3228,6 +3237,56 @@
 	die();
 }
 
+/**
+ * Kill WordPress execution and display JSON message with error message.
+ *
+ * This is the handler for wp_die when processing REST API requests.
+ *
+ * @since 5.1.0
+ * @access private
+ *
+ * @param string       $message Error message.
+ * @param string       $title   Optional. Error title. Default empty.
+ * @param string|array $args    Optional. Arguments to control behavior. Default empty array.
+ */
+
+function _rest_wp_die_handler( $message, $title = '', $args = array() ) {
+	$defaults = array( 'response' => 500, 'code' => 'wp_die_rest_handler' );
+
+	$r = wp_parse_args( $args, $defaults );
+
+	if ( ! headers_sent() ) {
+		$content_type = isset( $_GET['_jsonp'] ) ? 'application/javascript' : 'application/json';
+		$blog_charset = 'utf-8';
+		if ( function_exists( 'get_option' ) ) {
+			$blog_charset = get_option( 'blog_charset', 'utf-8' );
+		}
+		header( 'Content-Type: ' . $content_type . '; charset=' . $blog_charset );
+		if ( null !== $r['response'] ) {
+			status_header( $r['response'] );
+		}
+	}
+
+	$return = array(
+	     'code' => $r['code'],
+         'message' => $message,
+         'data' => array(
+              'status' =>  $r['response'],
+         )
+    );
+
+	$result = wp_json_encode($return);
+	$jsonp_callback = $_GET['_jsonp'];
+	if ( $jsonp_callback ) {
+		// Prepend '/**/' to mitigate possible JSONP Flash attacks.
+		// https://miki.it/blog/2014/7/8/abusing-jsonp-with-rosetta-flash/
+		echo '/**/' . $jsonp_callback . '(' . $result . ')';
+	} else {
+		echo $result;
+	}
+	die();
+}
+
 /**
  * Kill WordPress ajax execution.
  *
@@ -5073,7 +5132,6 @@
 		$exists[4] = ( $exists[1] && $exists[3] );
 		$exists[5] = ( $exists[2] && $exists[3] );
 
-		// phpcs:disable WordPress.WP.I18n.LowLevelTranslationFunction,WordPress.WP.I18n.NonSingularStringLiteralText
 		$zonen[] = array(
 			'continent'   => ( $exists[0] ? $zone[0] : '' ),
 			'city'        => ( $exists[1] ? $zone[1] : '' ),
@@ -5082,7 +5140,6 @@
 			't_city'      => ( $exists[4] ? translate( str_replace( '_', ' ', $zone[1] ), 'continents-cities' ) : '' ),
 			't_subcity'   => ( $exists[5] ? translate( str_replace( '_', ' ', $zone[2] ), 'continents-cities' ) : '' ),
 		);
-		// phpcs:enable
 	}
 	usort( $zonen, '_wp_timezone_choice_usort_callback' );
 
Index: src/wp-includes/load.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/wp-includes/load.php	(revision 44568)
+++ src/wp-includes/load.php	(date 1547299555000)
@@ -1271,6 +1271,42 @@
 	return apply_filters( 'wp_doing_ajax', defined( 'DOING_AJAX' ) && DOING_AJAX );
 }
 
+
+/**
+ * Determines whether the current request is a WordPress REST API request.
+ *
+ * @since 5.1.0
+ *
+ * @return bool True if it's a WordPress REST API request, false otherwise.
+ */
+function wp_doing_rest() {
+
+	if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) {
+		return true;
+	}
+	if ( ! function_exists( 'rest_get_url_prefix' ) ) {
+		return false;
+	}
+	$prefix = rest_get_url_prefix();
+	if ( isset( $_GET['rest_route'] ) && strpos( trim( $_GET['rest_route'], '\\/' ), $prefix, 0 ) === 0 ) {
+		return true;
+	}
+
+	$rest_url    = wp_parse_url( site_url( $prefix ) );
+	$current_url = wp_parse_url( add_query_arg( array() ) );
+
+	$wp_doing_rest = strpos( $current_url['path'], $rest_url['path'], 0 ) === 0;
+
+	/**
+	 * Filters whether the current request is a WordPress REST API request.
+	 *
+	 * @since 5.1.0
+	 *
+	 * @param bool $wp_doing_rest Whether the current request is a WordPress REST API request.
+	 */
+	return apply_filters( 'wp_doing_rest', $wp_doing_rest );
+}
+
 /**
  * Determines whether the current request should use themes.
  *
Index: src/wp-includes/rest-api.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/wp-includes/rest-api.php	(revision 44568)
+++ src/wp-includes/rest-api.php	(date 1547257473000)
@@ -301,7 +301,7 @@
 	$server->serve_request( $route );
 
 	// We're done.
-	die();
+	exit();
 }
 
 /**
