Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@


RewriteRule ^robots.txt$ static/robots.txt [L]
RewriteRule ^F static/rewrite.php [L]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment on the commit - fc3f2a4

RewriteRule ^cgi-bin/(.+)$ static/rewrite.php [L]

# Hold
RewriteRule ^(Record)/([^/]+)/(Hold)/(.+)$ index.php?module=$1&id=$2&action=$3&barcode=$4 [QSA,L]
Expand All @@ -63,6 +61,8 @@


RewriteRule ^([^/]+)/(.+)$ index.php?module=$1&action=$2 [QSA,L]

ErrorDocument 404 /index.php?module=Error&action=Error404
</IfModule>

# Disable Magic Quotes
Expand All @@ -72,6 +72,6 @@ php_value magic_quotes_gpc false
AddType application/x-httpd-php .css

## Uncomment these lines if you wish to show all errors on the screen.
php_value display_errors 1
php_value error_reporting 2047
# php_value display_errors 1
# php_value error_reporting 2047

2 changes: 0 additions & 2 deletions docker/nginx-default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ server {


rewrite ^/robots.txt$ /static/robots.txt last;
rewrite ^/F /static/rewrite.php last;
rewrite ^/cgi-bin/(.+)$ /static/rewrite.php last;


# Hold
Expand Down
24 changes: 9 additions & 15 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@
}
}


//################################
// HTStatus
//
Expand Down Expand Up @@ -311,10 +310,10 @@
$service = new $action();
$service->launch();
} else {
PEAR::raiseError(new PEAR_Error('Unknown Action'));
PEAR::raiseError(new PEAR_Error("Not found"));
}
} else {
PEAR::raiseError(new PEAR_Error("Cannot Load Action: module=$module, action=$action"));
PEAR::raiseError(new PEAR_Error("Not found"));
}


Expand All @@ -324,22 +323,17 @@

// Process any errors that are thrown
function handlePEARError($error, $method = null) {
$module = (isset($_GET['module'])) ? $_GET['module'] : 'Search';
$interface = new UInterface();
$interface->assign('error', $error);
$interface->assign('module', $module);
header('HTTP/1.1 404 Not Found');
// If the module was Bib API ("api") but the rewrite rules could not parse the URL
// then we could provide a developer error string in JSON form. For now, bail out.
$module = (isset($_GET['module'])) ? $_GET['module'] : 'error';

if ($module == 'api') {
header('HTTP/1.1 404 Not Found');
exit();
}
$interface->setTemplate('error.tpl');
$interface->display('layout.tpl');

foreach ($error->backtrace as $trace) {
echo '[' . $trace['line'] . '] ' . $trace['file'] . '<br>';
}
require_once "services/Error/Error404.php";
$service = new Error404();
$service->launch();

exit();
}

Expand Down
43 changes: 43 additions & 0 deletions interface/themes/firebird/Error/Error404.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<hathi-cookie-consent-banner></hathi-cookie-consent-banner>
<div id="skiplinks" class="visually-hidden-focusable" role="complementary" aria-label="Skip links">
<ul>
<li>
<a href="#section">Skip to main content</a>
</li>
</ul>
</div>
<div id="root">
{include file="header.tpl"}

<main class="main main-container error" id="main">

<div class="container error-wrapper">

<section id="section" class="d-flex flex-column">
<div class="d-flex flex-column message-wrapper">
<div class="d-flex flex-column-reverse gap-2">
<h1>Page not found</h1>
<h2 class="text-uppercase error-code">Error: 404</h2>
</div>

<p class="error-message">Sorry, we can't find the page you're looking for.</p>
</div>

<div class="d-flex flex-column gap-3 help-links">
<p>Here are a few links that may be helpful:</p>
<ul class="m-0 p-0 list-unstyled d-flex gap-3">
<li><a href="https://www.hathitrust.org">Home</a></li>
<li><a href="https://babel.hathitrust.org/cgi/ls?a=page&page=advanced">Advanced Search</a></li>
<li><a href="https://hathitrust.atlassian.net/servicedesk/customer/portals">Help Center</a></li>
<li>
<a href="#" data-hathi-trigger="hathi-feedback-form-modal" id="feedback-form">Report a Problem</a>
</li>
</ul>
</div>
<hathi-feedback-form-modal data-prop-form="error" data-prop-is-open="false"></hathi-feedback-form-modal>
</section>
</div>
</main>

{include file="footer.tpl"}
</div>
50 changes: 32 additions & 18 deletions interface/themes/firebird/Record/error.tpl
Original file line number Diff line number Diff line change
@@ -1,28 +1,42 @@
<hathi-cookie-consent-banner></hathi-cookie-consent-banner>
<ul id="skiplinks" class="visually-hidden-focusable" role="complementary" aria-label="Skip links">
<li>
<a href="#section">Skip to main</a>
</li>
</ul>
<div id="skiplinks" class="visually-hidden-focusable" role="complementary" aria-label="Skip links">
<ul>
<li>
<a href="#section">Skip to main content</a>
</li>
</ul>
</div>
<div id="root">
{include file="header.tpl"}

<main class="main-container" id="main">
{include file="search_form.tpl"}

<div class="container container-medium flex-container flex-container-expanded container-boxed" style="margin-top: 1.75rem; margin-bottom: 1.75rem">
<main class="main main-container error" id="main">

<section class="section-container" id="section">
<h1>
The catalog record could not be found.
</h1>
<div class="container error-wrapper">

<section id="section" class="d-flex flex-column">
<div class="d-flex flex-column message-wrapper">
<div class="d-flex flex-column-reverse gap-2">
<h1>Catalog record not found</h1>
<h2 class="text-uppercase error-code">Error: 404</h2>
</div>

<p>
No catalog record was found with that identifier. Please check your url or try searching HathiTrust.
</p>
</section>
</div>
<p class="error-message">Sorry, we can't find the record you're looking for.</p>
</div>

<div class="d-flex flex-column gap-3 help-links">
<p>Here are a few links that may be helpful:</p>
<ul class="m-0 p-0 list-unstyled d-flex gap-3">
<li><a href="https://www.hathitrust.org">Home</a></li>
<li><a href="https://babel.hathitrust.org/cgi/ls?a=page&page=advanced">Advanced Search</a></li>
<li><a href="https://hathitrust.atlassian.net/servicedesk/customer/portals">Help Center</a></li>
<li>
<a href="#" data-hathi-trigger="hathi-feedback-form-modal" id="feedback-form">Report a Problem</a>
</li>
</ul>
</div>
<hathi-feedback-form-modal data-prop-form="error" data-prop-is-open="false"></hathi-feedback-form-modal>
</section>
</div>
</main>

{include file="footer.tpl"}
Expand Down
12 changes: 7 additions & 5 deletions interface/themes/firebird/Search/error.tpl
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<hathi-cookie-consent-banner></hathi-cookie-consent-banner>
<ul id="skiplinks" class="visually-hidden-focusable" role="complementary" aria-label="Skip links">
<li>
<a href="#section">Skip to main</a>
</li>
</ul>
<div id="skiplinks" class="visually-hidden-focusable" role="complementary" aria-label="Skip links">
<ul>
<li>
<a href="#section">Skip to main content</a>
</li>
</ul>
</div>
<div id="root">
{include file="header.tpl"}

Expand Down
17 changes: 8 additions & 9 deletions playwright/test/slow/deleted_record.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,30 @@ const redirect_target_cid = '103192851';
const deleted_cid = '9999'; // arbitrary choice

test.describe('Deleted records', () => {

test.beforeAll(async ({ request }) => {
const solrDocsFd = await open('test/slow/deleted_record_test_docs.json');
const solrDocs = await solrDocsFd.readFile();
solrDocsFd.close();

const solrResponse = await(request.post('http://solr-sdr-catalog:9033/solr/catalog/update/json/docs?commit=true', { data: solrDocs, headers: { 'Content-Type': 'application/json' } } ));
const solrResponse = await request.post('http://solr-sdr-catalog:9033/solr/catalog/update/json/docs?commit=true', {
data: solrDocs,
headers: { 'Content-Type': 'application/json' },
});
expect(solrResponse.status()).toEqual(200);
});

test('redirects to another record with corresponding old_ids', async ({ request }) => {


// get old record ID; should redirect to new record
const recordResponse = await(request.get(`/Record/${redirect_cid}`, { maxRedirects: 0 }));
const recordResponse = await request.get(`/Record/${redirect_cid}`, { maxRedirects: 0 });
expect(recordResponse.status()).toEqual(301);
expect(recordResponse.headers().location).toEqual(`/Record/${redirect_target_cid}`)
expect(recordResponse.headers().location).toEqual(`/Record/${redirect_target_cid}`);
});

test('with no corresponding old_ids says no such catalog record', async ({ request }) => {
// no redirect, just not found
const recordResponse = await(request.get(`/Record/${deleted_cid}`, { maxRedirects: 0 }));
const recordResponse = await request.get(`/Record/${deleted_cid}`, { maxRedirects: 0 });
expect(recordResponse.status()).toEqual(404);
const responseBody = await recordResponse.text();
expect(responseBody).toMatch(/catalog record could not be found/);
expect(responseBody).toContain('Catalog record not found');
});

});
18 changes: 18 additions & 0 deletions services/Error/Error404.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

class Error404 {

function launch() {

$interface = new UInterface();
header('HTTP/1.1 404 Not Found');
$interface->assign('module', 'Error');
$interface->setPageTitle('Page not found');
$interface->setTemplate('Error404.tpl');
$interface->display('layout.tpl');

exit();
}
}

?>
4 changes: 3 additions & 1 deletion services/Record/Record.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Record extends Action
public $cacheId;

public $db;

public $inTemp = false;
public $inSubset = false;
public $isFavorite = false;
Expand All @@ -69,6 +69,7 @@ function __construct()

if (count($this->mergedItemData[1]['records']) == 0) {
header('HTTP/1.1 404 Not Found');
$interface->setPageTitle('Catalog record not found');
$interface->setTemplate('error.tpl');
$interface->display('layout.tpl');
exit;
Expand Down Expand Up @@ -129,6 +130,7 @@ function __construct()
if (!($record = $this->db->getRecord($this->id))) {
# PEAR::raiseError(new PEAR_Error('Record Does Not Exist'));
header('HTTP/1.1 404 Not Found');
$interface->setPageTitle('Catalog record not found');
$interface->setTemplate('error.tpl');
$interface->display('layout.tpl');
exit;
Expand Down
Loading