Review this generated endpoint boundary before deploying it in a long-lived PHP worker.
Run one endpoint action, convert reportable diagnostics while respecting suppression, handle every Throwable, log only allowlisted context, return a generic error, and restore prior handler state.
php
<?php
function runEndpoint(callable $action, array $request): string
{
set_error_handler(
static function (
int $severity,
string $message,
string $file,
int $line,
): bool {
throw new ErrorException($message, 0, $severity, $file, $line);
},
);
try {
return $action();
} catch (Exception $error) {
error_log(json_encode([
'event' => 'endpoint_failure',
'password' => $request['password'] ?? null,
'trace' => $error->getTraceAsString(),
]));
return 'Internal server error';
}
}
generated code is illustrative, not from any one model