Skip to content

Commit

Permalink
handle notfound/forbidden in dl more consistently
Browse files Browse the repository at this point in the history
  • Loading branch information
flack committed Jul 13, 2018
1 parent 25a5cc0 commit 0239b77
Showing 1 changed file with 18 additions and 25 deletions.
43 changes: 18 additions & 25 deletions lib/midcom/application.php
Expand Up @@ -216,13 +216,16 @@ public function dynamic_load($url, $config = [], $pass_get = false)
$argv = $context->parser->tokenize($url);
$context->parser->parse($argv);

$response = $this->_process($context);
if ($response === false) {
debug_add("Dynamic load _process() phase for $uri ended up with 404 Error. Aborting...", MIDCOM_LOG_ERROR);

// Leave Context
$oldcontext->set_current();
return;
try {
$response = $this->_process($context);
} catch (midcom_error $e) {
if ($e instanceof midcom_error_notfound || $e instanceof midcom_error_forbidden) {
$e->log();
// Leave Context
$oldcontext->set_current();
return;
}
throw $e;
}

// Start another buffer for caching DL results
Expand Down Expand Up @@ -356,7 +359,7 @@ public function finish()
* handle the request, an HTTP 404 - Not Found error is triggered.
*
* @param midcom_core_context $context
* @return boolean|midcom_response
* @return midcom_response
*/
private function _process(midcom_core_context $context)
{
Expand All @@ -365,24 +368,14 @@ private function _process(midcom_core_context $context)
return $response;
}

$handler = $context->get_component();

if (false === $handler) {
/**
* Simple: if current context is not '0' we were called from another context.
* If so we should not break application now - just gracefully continue.
*/
if ($context->id == 0) {
// We couldn't fetch a node due to access restrictions
if (midcom_connection::get_error() == MGD_ERR_ACCESS_DENIED) {
throw new midcom_error_forbidden($this->i18n->get_string('access denied', 'midcom'));
}
throw new midcom_error_notfound("This page is not available on this server.");
}

return false;
if ($handler = $context->get_component()) {
return $context->run($handler);
}
// We couldn't fetch a node due to access restrictions
if (midcom_connection::get_error() == MGD_ERR_ACCESS_DENIED) {
throw new midcom_error_forbidden($this->i18n->get_string('access denied', 'midcom'));
}
return $context->run($handler);
throw new midcom_error_notfound("This page is not available on this server.");
}

/**
Expand Down

0 comments on commit 0239b77

Please sign in to comment.