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
13 changes: 12 additions & 1 deletion lib/private/AppFramework/Http/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,18 @@ private function executeController(Controller $controller, string $methodName):
}

$this->eventLogger->start('controller:' . get_class($controller) . '::' . $methodName, 'App framework controller execution');
$response = \call_user_func_array([$controller, $methodName], $arguments);
try {
$response = \call_user_func_array([$controller, $methodName], $arguments);
} catch (\TypeError $e) {
// Only intercept TypeErrors occuring on the first line, meaning that the invocation of the controller method failed.
// Any other TypeError happens inside the controller method logic and should be logged as normal.
if ($e->getFile() === $this->reflector->getFile() && $e->getLine() === $this->reflector->getStartLine()) {
$this->logger->debug('Failed to call controller method: ' . $e->getMessage(), ['exception' => $e]);
return new Response(Http::STATUS_BAD_REQUEST);
}

throw $e;
}
$this->eventLogger->end('controller:' . get_class($controller) . '::' . $methodName);

if (!($response instanceof Response)) {
Expand Down
13 changes: 13 additions & 0 deletions lib/private/AppFramework/Utility/ControllerMethodReflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,18 @@ class ControllerMethodReflector implements IControllerMethodReflector {
private $types = [];
private $parameters = [];
private array $ranges = [];
private int $startLine = 0;
private string $file = '';

/**
* @param object $object an object or classname
* @param string $method the method which we want to inspect
*/
public function reflect($object, string $method) {
$reflection = new \ReflectionMethod($object, $method);
$this->startLine = $reflection->getStartLine();
$this->file = $reflection->getFileName();

$docs = $reflection->getDocComment();

if ($docs !== false) {
Expand Down Expand Up @@ -134,4 +139,12 @@ public function getAnnotationParameter(string $name, string $key): string {

return '';
}

public function getStartLine(): int {
return $this->startLine;
}

public function getFile(): string {
return $this->file;
}
}
Loading