diff --git a/modules/book/book.pages.inc b/modules/book/book.pages.inc
index 3e682ef2071b7c19f09ea599523103b30c0e6c4a..f6f7b0e8508b894722ff7a73c57645a35c27dc34 100644
--- a/modules/book/book.pages.inc
+++ b/modules/book/book.pages.inc
@@ -77,9 +77,11 @@ function book_export_html($nid) {
     if (isset($node->book)) {
       $tree = book_menu_subtree_data($node->book);
       $contents = book_export_traverse($tree, 'book_node_export');
+      return theme('book_export_html', array('title' => $node->title, 'contents' => $contents, 'depth' => $node->book['depth']));
+    }
+    else {
+      drupal_not_found();
     }
-
-    return theme('book_export_html', array('title' => $node->title, 'contents' => $contents, 'depth' => $node->book['depth']));
   }
   else {
     drupal_access_denied();
diff --git a/modules/book/book.test b/modules/book/book.test
index c797b7badb4b98429d7de4f1df57408d51e4b8a0..6ac63f0600481de4c7e150f84b52252f15784779 100644
--- a/modules/book/book.test
+++ b/modules/book/book.test
@@ -237,6 +237,10 @@ class BookTestCase extends DrupalWebTestCase {
     $this->drupalGet('book/export/foobar/' . $this->book->nid);
     $this->assertResponse('404', t('Unsupported export format returned "not found".'));
 
+    // Make sure we get a 404 on a not existing book node.
+    $this->drupalGet('book/export/html/123');
+    $this->assertResponse('404', t('Not existing book node returned "not found".'));
+
     // Make sure an anonymous user cannot view printer-friendly version.
     $this->drupalLogout();