Skip to content
Open
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
54 changes: 53 additions & 1 deletion src/StreamingServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,12 @@ function ($error) use ($that, $conn, $request) {
$exception = new \RuntimeException($message, null, $previous);

$that->emit('error', array($exception));
return $that->writeError($conn, 500, $request);
//return $that->writeError($conn, 500, $request);
try {
return $that->fcWriteError($conn, $error, $request);
} catch (Throwable $e) {
return $that->writeError($conn, 500, $request);
}
}
);
}
Expand All @@ -320,6 +325,53 @@ public function writeError(ConnectionInterface $conn, $code, ServerRequestInterf

$this->handleResponse($conn, $request, $response);
}

/** @internal */
public function fcWriteError(ConnectionInterface $conn, $e, ServerRequestInterface $request) {
// filter out the server information in trace
$traceStr = $e->getTraceAsString();
$pos = strpos($traceStr, "/var/fc/runtime/php7/src/server.php");
$traceStr = substr($traceStr, 0, $pos);
$err = array(
"errorMessage" => $e->getMessage(),
"errorType" => get_class($e),
"stackTrace" => array(
"file" => $e->getFile(),
"line" => $e->getLine(),
"traceString" => $traceStr,
),
);

var_export($err);
if (ob_get_length()) ob_clean();
echo 'FC Invoke End RequestId: ' . $GLOBALS['requestId'] . PHP_EOL;
unset($GLOBALS['requestId']);

$errStr = json_encode($err, JSON_UNESCAPED_UNICODE);
$response = new Response(
404,
array(
'Content-Type' => 'application/octet-stream',
'Content-Length' => strlen($errStr),
'Connection' => 'keep-alive',
),
$errStr
);

// append reason phrase to response body if known
$reason = $response->getReasonPhrase();
if ($reason !== '') {
$body = $response->getBody();
$body->seek(0, SEEK_END);
$body->write(': ' . $reason);
}

if ($request === null) {
$request = new ServerRequest('GET', '/', array(), null, '1.1');
}

$this->handleResponse($conn, $request, $response);
}


/** @internal */
Expand Down